目前,我有一个定义如下的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在现实中并没有那么简单,所以我不想仅仅为此单独制作VirtualHosts。在VirtualHost中是否有条件表达式或类似的表达式可以使用?与…有关的东西:
<VirtualHost *:80>
...
<If ServerName=otherdomain.com>
Alias /sub /var/www/other
</If>
</VirtualHost>发布于 2017-06-20 13:47:02
不,不能在If中使用别名。
If "%{HTTP_HOST}与Alias不兼容,使用它将导致Apache没有启动和输出错误消息:
Alias not allowed here您应该创建另一个具有相应名称的VirtualHost,并使用您的别名进行配置。
发布于 2012-08-13 18:52:10
下面是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>我相信您将需要Apache2.2或更高版本的"If“功能。
发布于 2022-01-06 23:20:37
我想我已经找到了一条路。
<Directory /var/www/other>
Require all denied
<If "%{HTTP_HOST} == 'example.com'>
Require all granted
</If>
</Directory>
Alias /sub /var/www/other<If> +在/var/www/other内的.htaccess文件中的要求也应该可以工作。
https://serverfault.com/questions/417103
复制相似问题