Set Apache Alias for specific ServerAlias

aliasapache-2.2serveralias

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>

Best Answer

No you cannot use an alias in a If.

If "%{HTTP_HOST}

is not compatible with Alias, using it will result with Apache not starting and outputting the error message:

Alias not allowed here

You should create another VirtualHost with the corresponding name and configured with your alias.