简体   繁体   English

htaccess 不重定向到自定义 404 页面

[英]htaccess not redirecting to custom 404 page

I have a custom 404 page called 404page.php , and I have the htaccess file with the line that I found should work (this is the only line I have in the .htaccess file)我有一个名为 404page.php 的自定义 404 页面,我有一个 htaccess 文件,我发现该行应该可以工作(这是我在 .htaccess 文件中唯一的一行)

ErrorDocument 404 /404page.php

It was working fine yesterday, but today I was optimizing images and some other stuff on the website, and when I reuploaded it, the htaccess didn't redirect to 404page.php anymore, but to a page that has this written:昨天它运行良好,但今天我正在优化网站上的图像和其他一些东西,当我重新上传它时,htaccess 不再重定向到 404page.php,而是重定向到一个页面,上面写着:

Not Found未找到

The requested URL /asfsdtg was not found on this server.在此服务器上找不到请求的 URL /asfsdtg。

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

(I just typed asfsdtg to test if it was working). (我只是输入 asfsdtg 来测试它是否有效)。

The website is uploaded online and I'm managing it through cpanel (I'm still a beginner).网站是在线上传的,我是通过cpanel管理的(我还是个初学者)。 I searched for some solutions, I tried adding another line to .htaccess, then it looked like this:我搜索了一些解决方案,我尝试在 .htaccess 中添加另一行,然后它看起来像这样:

RewriteEngine on
ErrorDocument 404 /404page.php

I even tried putting the location of the 404page.php as a local link, and the internet link, and it still gave me the weird error page.我什至尝试将 404page.php 的位置作为本地链接和互联网链接,但它仍然给了我奇怪的错误页面。

Does anyone have some idea whats happening?有谁知道发生了什么? If you need more info that I didn't supply please tell me what more I can supply如果您需要更多我没有提供的信息,请告诉我我还能提供什么

Try out this:试试这个:

RewriteEngine on
ErrorDocument 404   http://yoursitename.com/404page.php

And be sure that 404page.php exists on the root of your server and is trully called 404page.php not 404Page.php并确保404page.php存在于您的服务器的根目录中,并且404page.php称为404page.php而不是404Page.php

Be carefull at the characters, this is key sensitive!小心字符,这是关键敏感!

Try with like this:像这样尝试:

RewriteEngine on
ErrorDocument 404   http://www.sitename.com/404.php

Make to handle any 404 errors.处理任何 404 错误。

ErrorDocument 404 /404page.php

If above setting does not works you have to write addition line of code as mentions below.如果上述设置不起作用,您必须编写如下所述的附加代码行。 Which identifies for non existing files and directories and redirect to 404.它标识不存在的文件和目录并重定向到 404。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ - [R=404,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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