Apache ErrorDocument绝对路径
我尝试对域及其所有子域使用相同的 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 工作、符号链接已启用
I'm trying to use the same 404 ErrorDocument for a domain and all its subdomains,
The subdomains all have their own directory in the /var/www/ path
the Apache ErrorDocument directive expects a relative path (relative to the current directory) but I want it to
go to /var/www/ErrorPages/404.html from all directories/subdomains
There is a similar question here asked in 2010 but it does not eleborate on the solution, I have tried Alias and couldn't get it to do what I want.
Example 1:
file http://example.com/doesnotexist.txt
requested
-> show /var/www/mervin/ErrorDocuments/404.html
as response
Example 2:
file http://subdomain.example.com/otherimaginaryfile.txt
requested
-> show /var/www/ErrorPages/404.html
as response
Virtualhost:
<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>
How would I go about doing this?
Other info: Apache2.2, MOD_ALIAS working, MOD_REWRITE working, Symbolic Links enabled
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在我的一个开发箱上设置了一个测试配置 - 我注意到你的开发箱中缺少的主要内容是你的错误文档的目录声明!
这适用于我的设置:
让您的 Alias/ErrorDocs 内容适用于您的主域,然后如果别名仍然存在问题,我们可以解决这个问题 [尽管我有一种感觉,一旦添加目录 - 一切都会陷入困境地方! ;)]
-肖恩
I setup a test configuration on one of my dev boxes - the main thing I notice missing from yours is a Directory declaration for your error docs!!
This works for my setup:
Get your Alias/ErrorDocs stuff working for your main domain, then if there is still trouble with the aliases, we can work on that [though I have a feeling that once you add the directory - everything will fall into place! ;) ]
-sean