多个VHost的通用重写设置

发布于 2024-07-26 16:13:30 字数 1035 浏览 12 评论 0原文

我正在启用站点的文件夹中使用多个虚拟主机运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄人书 2024-08-02 16:13:30

您可以尝试 AliasMatch

AliasMatch ^/(robots\.txt|favicon.ico)$ /home/sites/site1/www/mainsite_alias$0

You could try a AliasMatch:

AliasMatch ^/(robots\.txt|favicon.ico)$ /home/sites/site1/www/mainsite_alias$0
各自安好 2024-08-02 16:13:30

我正在使用这个

<VirtualHost *:80>
    ServerAdmin email_at_isp
    DocumentRoot "C:/apache/htdocs"  
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin_at_server_one.com
    DocumentRoot "C:/apache/htdocs/server_one.com"
    ServerName server_one.com
    ErrorLog "logs/server_one.com-error.log"
    CustomLog "logs/server_one.com-access.log" common
</VirtualHost>

,并且我在根目录的 .htaccess 中不断重写脚本[C:/apache/htdocs]
我希望它能以某种方式有所帮助,即使不是令人厌烦。 哈哈

I am using this

<VirtualHost *:80>
    ServerAdmin email_at_isp
    DocumentRoot "C:/apache/htdocs"  
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin_at_server_one.com
    DocumentRoot "C:/apache/htdocs/server_one.com"
    ServerName server_one.com
    ErrorLog "logs/server_one.com-error.log"
    CustomLog "logs/server_one.com-access.log" common
</VirtualHost>

and I keep rewrite scripts in .htaccess at the root[C:/apache/htdocs]
I hope it helps somehow, if not enoying. lol

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文