简体   繁体   中英

Is it possible to set ErrorDocument in Apache httpd for defined alias?

Background:

I have an apache configuration file on my webserver and it has a route address and then a number of alias' defined. The issue i have is that in the event of a 404 the user is re-directed to the root site even when using the alias portal, which looking at the configuration file makes sense.

Question

How can i define the ErrorDocument settings for each of my aliases?

Source Code

<VirtualHost *:80>

        ServerAlias *.samplesite.mysite.mycompany.co.uk
        UseCanonicalName Off
        ErrorDocument 404 /404.html
        DocumentRoot /var/www/html/mysite1

AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript text/javascript application/json

        Alias /mysite2 /var/www/html/mysite2
        Alias /mysite3 /var/www/html/mysite3
        Alias /mysite4 /var/www/html/mysite4

        <Directory "/var/www/html/mysite1">
                Require all granted
                Options +Indexes
        </Directory>

        LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
        CustomLog logs/mysite_access_log vcommon

        LogLevel  info
        #LogLevel  debug rewrite:trace6
    ErrorLog "logs/mysite-error.log"

</VirtualHost>

ok so i found the answer, will post just incase its useful to anyone else:

Alias /mysite2 /var/www/html/mysite2
<Directory "/var/www/html/mysite2">
ErrorDocument 404 /mysite2/404.html 
Require all granted
Options +Indexes
</Directory>

Alias /mysite3 /var/www/html/mysite3
<Directory "/var/www/html/mysite3">
ErrorDocument 404 /mysite3/404.html 
Require all granted
Options +Indexes
</Directory>

Alias /mysite4 /var/www/html/mysite4
<Directory "/var/www/html/mysite4">
ErrorDocument 404 /mysite4/404.html 
Require all granted
Options +Indexes
</Directory>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM