开发者

Apache ErrorDocument absolute path

开发者 https://www.devze.com 2023-03-24 03:14 出处:网络
I\'m trying to us开发者_JAVA百科e the same 404 ErrorDocument for a domain and all its subdomains,

I'm trying to us开发者_JAVA百科e 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消