.htaccess ErrorDocument 404 未显示 [英] .htaccess ErrorDocument 404 not showing up

查看:41
本文介绍了.htaccess ErrorDocument 404 未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台运行在 Linux ubuntu 上的 AWS EC2 服务服务器,我已经安装了 apache、php 和 mysql.

I have a server from AWS EC2 service running on Linux ubuntu and I have installed apache, php, and mysql.

我在文档根目录 /var/www/html 中添加了一个 .htaccess 文件.

I have added a .htaccess file in my document root /var/www/html.

我在里面输入了这个代码:ErrorDocument 404/var/www/html/404.php 它仍然没有显示出来.

I entered this code in it: ErrorDocument 404 /var/www/html/404.php and it is still not showing up.

我多次输入此命令:sudo service httpd restart 重新启动服务器但未显示任何更改...

I kept entered this command multiple times: sudo service httpd restart to restart the server but no changes displayed...

我该如何解决这个问题...我做错了什么?

How can I fix this... Did I do something wrong?

推荐答案

首先,请注意,.htaccess 文件不需要重新启动 httpd..htaccess 文件是专门为没有root 权限的人设计的——即,无法访问httpd 服务器配置文件,并且无法重新启动服务器.由于您可以重新启动服务器,因此您不需要 .htaccess 文件,可以直接使用主服务器配置.

First, note that restarting httpd is not necessary for .htaccess files. .htaccess files are specifically for people who don't have root - ie, don't have access to the httpd server config file, and can't restart the server. As you're able to restart the server, you don't need .htaccess files and can use the main server config directly.

其次,如果 .htaccess 文件被忽略,您需要检查 AllowOverride 是否设置正确.参见 http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride 了解详情.您还需要确保它设置在正确的范围内 - 即在您的配置中的正确块中.例如,请确保您编辑块中的那个.

Secondly, if .htaccess files are being ignored, you need to check to see that AllowOverride is set correctly. See http://httpd.apache.org/docs/2.4/mod/core.html#allowoverride for details. You need to also ensure that it is set in the correct scope - ie, in the right block in your configuration. Be sure you're NOT editing the one in the block, for example.

第三,如果你想确保 .htaccess 文件实际上正在被读取,请将垃圾放入其中.当您将浏览器指向包含该文件的目录时,.htaccess 文件中的无效行(例如INVALID LINE HERE")将导致 500 服务器错误.如果没有,那么您没有正确配置 AllowOverride.

Third, if you want to ensure that a .htaccess file is in fact being read, put garbage in it. An invalid line, such as "INVALID LINE HERE", in your .htaccess file, will result in a 500 Server Error when you point your browser at the directory containing that file. If it doesn't, then you don't have AllowOverride configured correctly.

这篇关于.htaccess ErrorDocument 404 未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆