是否可以在 Apache httpd 中为定义的别名设置 ErrorDocument?
Is it possible to set ErrorDocument in Apache httpd for defined alias?
背景:
我的网络服务器上有一个 apache 配置文件,它有一个路由地址,然后定义了一些别名。我遇到的问题是,如果出现 404,即使使用别名门户,用户也会被重定向到根站点,查看配置文件很有意义。
问题
如何为每个别名定义 ErrorDocument 设置?
源代码
<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>
好的,所以我找到了答案,post 以防万一它对其他人有用:
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>
背景:
我的网络服务器上有一个 apache 配置文件,它有一个路由地址,然后定义了一些别名。我遇到的问题是,如果出现 404,即使使用别名门户,用户也会被重定向到根站点,查看配置文件很有意义。
问题
如何为每个别名定义 ErrorDocument 设置?
源代码
<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>
好的,所以我找到了答案,post 以防万一它对其他人有用:
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>