我正在尝试为域及其所有子域使用相同的404 ErrorDocument, 子域都在/ var / www / path
中有自己的目录Apache ErrorDocument指令需要一个相对路径(相对于当前目录),但我想要它 从所有目录/子域
转到/var/www/ErrorPages/404.html2010年有一个类似的问题here,但它没有详细说明解决方案,我尝试过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正常工作,启用符号链接
答案 0 :(得分: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工作为您的主域工作,然后如果仍然有别名的麻烦,我们可以解决[虽然我有一种感觉,一旦你添加目录 - 一切都将落实到位! ;)]
-Sean