Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to do this

<VirtualHost *>
    DocumentRoot /var/www/myDomain

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

So will read files from a different directory. The above will not work so, how can I do this without moving the files?

share|improve this question
up vote 7 down vote accepted

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
share|improve this answer
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 '09 at 2:04
In the directory section for /var/www/mydomain add "AllowOverride All" – theotherreceive Jul 10 '09 at 3:26

Do it like this:

<VirtualHost *>
  DocumentRoot /var/www/myDomain
  Alias /blog/ /var/www/myBlog/
share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.