多个VHost的通用重写设置
我正在启用站点的文件夹中使用多个虚拟主机运行 Apache2,每个虚拟主机看起来都有点像这样:
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /home/sites/site1/www/
<Directory /home/sites/site/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
<Directory /home/sites/mainsite/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
# Provide default favicon.ico and robots.txt using rewrite
RewriteOptions Inherit
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^/(robots\.txt|favicon\.ico)$ /mainsite_alias$0 [PT,NC,L]
</VirtualHost>
重写代码对于所有虚拟主机都是通用的(提供默认的 favicon.ico/robots.txt),但是将此代码放入 httpd.conf 中确实如此似乎没有任何效果 - 重写日志没有显示任何内容。
如何使该代码对所有虚拟主机通用而不重复代码?
或者 - 有没有更好的方法来实现默认的图标?
谢谢
I am running Apache2 with multiple vhosts in the sites-enabled folder, each looks a bit like this:
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /home/sites/site1/www/
<Directory /home/sites/site/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
<Directory /home/sites/mainsite/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
# Provide default favicon.ico and robots.txt using rewrite
RewriteOptions Inherit
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^/(robots\.txt|favicon\.ico)$ /mainsite_alias$0 [PT,NC,L]
</VirtualHost>
The Rewrite code is common to all vhosts (providing a default favicon.ico/robots.txt) but putting this code into httpd.conf does not seem to have any effect - the rewrite logs show nothing.
How can I make this code common to all vhosts without duplicating the code?
Alternatively - is there a better way of achieving default favicons?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试
AliasMatch
:You could try a
AliasMatch
:我正在使用这个
,并且我在根目录的 .htaccess 中不断重写脚本[C:/apache/htdocs]
我希望它能以某种方式有所帮助,即使不是令人厌烦。 哈哈
I am using this
and I keep rewrite scripts in .htaccess at the root[C:/apache/htdocs]
I hope it helps somehow, if not enoying. lol