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.

Currently, I have a VirtualHost defined like so:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias otherdomain.com
    DocumentRoot /var/www/project/
</VirtualHost>

How can I make an Alias that only affects the otherdomain.com domain:

Alias /sub /var/www/other

So that:

http://otherdomain.com/sub -> /var/www/other
http://mydomain.com/sub -> /var/www/project/sub

The VirtualHost in question is not that simple in reality, so I'd rather not make separate VirtualHosts just for this. Are there any conditional expressions or similar that I can use inside the VirtualHost? Something along the lines of:

<VirtualHost *:80>
    ...
    <If ServerName=otherdomain.com>
        Alias /sub /var/www/other
    </If>
</VirtualHost>
share|improve this question
    
Can you clarify what your configuration needs are? From what you've provided, it seems like a poster child for separate vhosts.. but what you're looking for can probably be done with mod_rewrite and a single vhost if needed. –  Shane Madden Aug 14 '12 at 6:07
add comment

1 Answer

Here are the relevant bits of the Apache documentation:

http://httpd.apache.org/docs/trunk/mod/core.html#if

and

http://httpd.apache.org/docs/trunk/expr.html

In that case, something like this should work:

<If "%{HTTP_HOST} == 'example.com'">
    Alias /sub /var/www/other
</If>

I believe you will need Apache 2.2 or greater for the "If" functionality.

share|improve this answer
1  
You're going to need at least Apache 2.4 to use that directive. –  erickzetta Aug 13 '12 at 19:02
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.