1

I'm looking to do this

<VirtualHost *>
    ServerName myDomain.com
    DocumentRoot /var/www/myDomain

    <Directory /var/www/myDomain>
         Rewrite on
         RewriteRule ^blog/(.*)$ /var/www/myBlog/$1 [L]
    </Directory>
</VirtualHost>

So http://www.myDomain.com/blog/ will read files from a different directory. The above will not work so, how can I do this without moving the files?

3 Answers 3

7

There's no need to user mod_rewrite for this. Alias is better suited.

# Alias: Maps web paths into filesystem paths and is used to
# access content that does not live under the DocumentRoot.
Alias /blog /var/www/myBlog

If you want to change settings for just your blog, add a location directive.

<Location /blog>
    Allowoverride All
</Location>
2
  • This works in that it gives me access to the files, but it doesn't seem to read the .htacess file. Any ideas?
    – Scott
    Jul 10, 2009 at 2:04
  • 1
    In the directory section for /var/www/mydomain add "AllowOverride All" Jul 10, 2009 at 3:26
2

Do it like this:

<VirtualHost *>
  ServerName myDomain.com
  DocumentRoot /var/www/myDomain
  Alias /blog/ /var/www/myBlog/
</VirtualHost>
1

Location tags are just a generic container for Apache directives so use it to 'wrap' whatever you want to apply to that 'external view' section of the website. Very useful if you're pulling content from multiple physical directories into one larger structure, you can apply the same set of rules to all of them, instead of having multiple Directory entries

Alias directive is a simple redirect, great for long paths showing up as short and neat pointers.

DocumentRoot directive sets the top web content directory.

All of them deal with directories, but they're all a bit different. Location is mostly for dealing with what I'd call the 'web view'--how it's visible from the outside. Directory is for the 'physical view' of dealing with actual directories on the filesystem. If contents of one directory get served out as one URL, then there isn't a functional difference between them.

However, once you start 'composing' multiple directories, serving them out of multiple URL's that don't necessairly mirror their filesystem hierarchy, you need to mix and match all these directives for the desired effect. Just because two directives might behave the same in one situation, doesn't mean they're going to behave the same way in another.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .