Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

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
</Location>
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
1  
In the directory section for /var/www/mydomain add "AllowOverride All" –  theotherreceive Jul 10 '09 at 3:26
add comment

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
add comment

Do it like this:

<VirtualHost *>
  ServerName myDomain.com
  DocumentRoot /var/www/myDomain
  Alias /blog/ /var/www/myBlog/
</VirtualHost>
share|improve this answer
add comment

Your Answer

 
discard

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.