4

我正在尝试对域及其所有子域使用相同的 404 ErrorDocument,子域在 /var/www/ 路径中都有自己的目录

Apache ErrorDocument 指令需要一个相对路径(相对于当前目录),但我希望它从所有目录/子域转到 /var/www/ErrorPages/404.html

在 2010 年问了一个类似的问题但它没有详细说明解决方案,我尝试了 Alias,但无法让它做我想做的事。

示例 1:http://example.com/doesnotexist.txt请求的文件

-> 显示/var/www/mervin/ErrorDocuments/404.html为响应

示例 2:http://subdomain.example.com/otherimaginaryfile.txt请求的文件

-> 显示/var/www/ErrorPages/404.html为响应

虚拟主机:

<VirtualHost *:80>
ServerName www.mervinkoops.net
ServerAlias mervinkoops.net *.mervinkoops.net spirecoder.com www.spirecoder.com *.spirecoder.com
DocumentRoot /var/www/mervin
ErrorDocument 404 /ErrorDocuments/404.html
Redirect 404 /favicon.ico
RewriteEngine On
RewriteCond %{HTTP_HOST} public\.mervinkoops\.net [NC]
RewriteRule ^(.*)$ /public/$1 [L]
RewriteCond %{HTTP_HOST} pma\.mervinkoops\.net [NC]
RewriteRule ^(.*)$ /PHPMyAdmin/$1 [L]
RewriteCond %{HTTP_HOST} www\.mervinkoops\.net [NC]
RewriteRule ^(.*)$ /website/$1 [L]
RewriteCond %{HTTP_HOST} mervinkoops\.net [NC]
RewriteRule ^(.*)$ /website/$1 [L]
RewriteCond %{HTTP_HOST} www\.spirecoder\.com [NC]
RewriteRule ^(.*)$ /website/$1 [L]
RewriteCond %{HTTP_HOST} spirecoder\.com [NC]
RewriteRule ^(.*)$ /website/$1 [L]
<Directory /var/www/mervin/>
allow from all
Options -Indexes
RewriteBase /
</Directory>
</VirtualHost>

我该怎么做呢?

其他信息:Apache2.2,MOD_ALIAS 工作,MOD_REWRITE 工作,启用符号链接

4

1 回答 1

8

我在我的一个开发箱上设置了一个测试配置——我注意到你的主要缺少的是你的错误文档的目录声明!

这适用于我的设置:

<VirtualHost *:80>

        ServerName stackexchange.nexus.local
        ServerAlias serverfault.nexus.local

        DocumentRoot /Data/vhome/stackexchange.nexus.local/httpdocs

        HostnameLookups Off
        UseCanonicalName Off
        ServerSignature On

        ErrorLog /var/log/apache2/error_log
        CustomLog /var/log/apache2/access_log combined


        Alias "/ErrorPages" "/Data/vhome/stackexchange.nexus.local/ErrorPages/"
        ErrorDocument 400 /ErrorPages/bad_request.html
        ErrorDocument 401 /ErrorPages/bad_request.html
        ErrorDocument 403 /ErrorPages/bad_request.html
        ErrorDocument 404 /ErrorPages/bad_request.html


        <Directory /Data/vhome/stackexchange.nexus.local/httpdocs/>
                AllowOverride All
                Options +ExecCGI -Includes
                Order allow,deny
                Allow from all
                RewriteBase /
        </Directory>


        <Directory /Data/vhome/stackexchange.nexus.local/ErrorPages/>
                AllowOverride All
                Options +ExecCGI -Includes
                Order allow,deny
                Allow from all
        </Directory>

        #RewriteEngine On
        #RewriteCond %{HTTP_HOST} public\.mervinkoops\.net [NC]
        #RewriteRule ^(.*)$ /public/$1 [L]
        #RewriteCond %{HTTP_HOST} pma\.mervinkoops\.net [NC]
        #RewriteRule ^(.*)$ /PHPMyAdmin/$1 [L]
        #RewriteCond %{HTTP_HOST} www\.mervinkoops\.net [NC]
        #RewriteRule ^(.*)$ /website/$1 [L]
        #RewriteCond %{HTTP_HOST} mervinkoops\.net [NC]
        #RewriteRule ^(.*)$ /website/$1 [L]
        #RewriteCond %{HTTP_HOST} www\.spirecoder\.com [NC]
        #RewriteRule ^(.*)$ /website/$1 [L]
        #RewriteCond %{HTTP_HOST} spirecoder\.com [NC]
        #RewriteRule ^(.*)$ /website/$1 [L]


</VirtualHost>

让您的 Alias/ErrorDocs 内容适用于您的主域,然后如果别名仍然存在问题,我们可以解决此问题 [尽管我有一种感觉,一旦您添加了目录 - 一切都会到位!;) ]

-肖恩

于 2011-08-01T18:04:41.527 回答