Apache ErrorDocument绝对路径

发布于 2024-11-27 06:11:05 字数 1643 浏览 0 评论 0原文

我尝试对域及其所有子域使用相同的 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 技术交流群。

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

发布评论

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

评论(1

溺孤伤于心 2024-12-04 06:11:05

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

这适用于我的设置:

<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 内容适用于您的主域,然后如果别名仍然存在问题,我们可以解决这个问题 [尽管我有一种感觉,一旦添加目录 - 一切都会陷入困境地方! ;)]

-肖恩

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:

<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>

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

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