404 custom error page redirect doesn't show missing file URL

蹲街弑〆低调 提交于 2019-12-06 15:39:43

If your error pages are redirected to a PHP powered 404 page then the variable $_SERVER["HTTP_REFERER"] should contain something interesting. Having said that, redirecting to a error-404 page is a bad practice. It confuses search engines and human visitors alike.

Edit

Here is a solution that works on Apache. Add this line to your .htaccess file:

ErrorDocument 404 /error-404.php

Create a file called error-404.php in the root directory of your website with the following content:

<?php
echo "<h1>404 Not Found</h1>";
echo "<p>The page {$_SERVER['REQUEST_URI']} was not found on this server</p>";

What Salman A posted works for me.

It only worked though when I used a relative path in the .htaccess file:

ErrorDocument 404 /error-404.php

and not ErrorDocument 404 http://www.mydomain.com/error-404.php

The second version was giving me the redirected url in the address bar and in the page body.

Also, you don't need to use a php page for your 404 message; an html page works as well if you don't want to echo the URL in the body of the page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!