1

I have apache rewriting engine module turned on and a custom 404 error page configured this way on .htaccess file: ErrorDocument 404 /not_found.php

When I try to access to some page that do not exist the 404 error page is displayed. My problem is that I want the URL on address bar to be updated instead of having the non-existent URL. How can I do this? Thanks

2
  • 2
    Why would you want that? This is a bad idea in regard to search engines, which will, if you redirect to the URL of your 404 script, not get to see a 404 status code for the resource they originally requested – which will make them think, that resource might actually exist. Commented Nov 22, 2015 at 18:17
  • So you are telling me that this is the normal behaviour? Having a page loaded and a URL of a non existing one.. Commented Nov 22, 2015 at 18:41

1 Answer 1

3

This would work: .htaccess:

ErrorDocument 404 /my404redirect.htm

my404redirect.htm:

<html>
    <head>
        <meta http-equiv="refresh" content="0;URL=/not_found.php" />
    </head>
</html>

This would show a 404 the my404redirect.htm which redirects the user to you not_found.php. It's not the finest way, but it works fast and easy. You should also add a in your robots.txt a line to prevent search engines from showing your 404 file.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply :) This should work but what I really want to know is if it is possible to do that without a redirect..
I can't say that this is true, but I the URL that is shown in your browser is independent from the server. The server will never send the URL that has to be shown in your browser, so the only way to change the URL would be a redirect. (Please correct me if I'm wrong.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.