为特定的ServerAlias设置Apache别名

目前,我有一个像这样定义的VirtualHost:

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

如何制作只影响otherdomain.com网域的别名

 Alias /sub /var/www/other 

以便:

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

所讨论的VirtualHost在现实中并不那么简单,所以我宁愿不为此而单独制作VirtualHost。 有没有任何条件expression式或类似的,我可以在VirtualHost中使用? 有些东西是:

 <VirtualHost *:80> ... <If ServerName=otherdomain.com> Alias /sub /var/www/other </If> </VirtualHost> 

以下是Apache文档的相关部分:

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

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

在这种情况下,应该这样工作:

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

我相信你将需要Apache 2.2或更高的“If”function。

不,你不能在If中使用别名。

 If "%{HTTP_HOST} 

与Alias不兼容,使用它将导致Apache不启动并输出错误消息:

 Alias not allowed here 

你应该使用相应的名称创build另一个VirtualHost,并使用你的别名进行configuration。