Set Apache Alias for specific ServerAlias
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>
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.
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.