将index.html重定向到404错误页面时,Apache不会加载任何页面

时间:2017-08-17 13:35:09

标签: apache configuration-files

我在Apache服务器和Ubuntu机器上托管了一个网站。当访问者输入mydomain.com/index.html时,我想将其重定向到自定义404页面错误。 所以在/etc/apache2/sites-available我以下面的方式编辑mydomain.com.conf文件:

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ErrorDocument 403 /custom_403.html
    ErrorDocument 404 /custom_404.html
    Redirect      404 /index.html

但是现在当我输入www.mydomain.com时,Apache既没有加载index.html也没有加载custom_404.html。相反,它显示了我在DocumentRoot中的文件夹结构。

如果没有这个问题我怎么能实现我的目标? 感谢

1 个答案:

答案 0 :(得分:0)

我找到了一种方法来阻止用户通过编写mydomain.com/index.html来访问该网站。我编辑了文件/etc/apache2/mods-available/dir.conf,在写入DirectoryIndex的行中,我将index.html更改为somethingElse.html。然后在DocumentRoot中,我还将index.html的名称更改为somethingElse.html。 我保留了文件/etc/apache2/sites-available/mydomain.com.conf的配置,因此每次用户键入mydomain.com/index.html时,都会收到404错误自定义页面。

相关问题