这是我的另一篇文章的延续: 抓住所有VirtualHost不工作 。
我有虚拟主机的工作。 但是,我知道如何让它redirect一个自定义的错误页面,如404。
在我的VirtualHost中添加Redirect 404 / ,它将我带到默认的404页面。 但是,当我启用ErrorDocument 404 /errors/index.php我得到以下错误
Not Found The requested URL / was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
以下是我的configuration
<VirtualHost *:80> DocumentRoot /var/www/main ServerName null Redirect 404 / ErrorDocument 404 /errors/index.php ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
这是因为即使尝试访问/errors/index.php您的Redirect 404 /也会/errors/index.php 。
当给404 Not Found ,你不需要redirect到根。 我build议在/ ie /index.html为非现有的虚拟主机提供可读的错误消息,正常的为200 OK并且使用ErrorDocument 404 /为所有其他URL提供与404相同的内容。 当您已经给出404 Not Found时,位置不需要改变。
<VirtualHost *:80> ServerName null DocumentRoot /var/www/main ErrorDocument 404 / ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>