Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should 404 pages retain the URL or be redirected?

Some websites retain the URL path when a path is accessed that isn't found and when the page loads they simply display an error title, message and also set the HTTP status code to 404.

Other pages redirect it to a fixed 404 URL path which displays both the content and the header.

My questions are:

  • Should the URL not change so that the URL path is categorized as 404 for as long until the http response expires?
  • Should there ALWAYS be a 404 status code?
  • And even when a redirection occurs, then should the resulting page contain a 404 status code?

Or is it better to return a 404 response and include a location header pointing to the dedicated 404 URL (I'm not sure if its possible to mix redirections and 400-series status codes)?

like image 352
matsko Avatar asked Nov 29 '25 04:11

matsko


1 Answers

If the page that your server is returning is a "File Not Found", it should return a 404 error. Adding in a redirect seems pointless and confusing to web-crawlers and people alike.

With Apache you can retain the original URL, return a 404 and have a custom error message if you add this to your .htaccess file in the root of your webserver:

ErrorDocument 404 /notfound.html

Where notfound.html is your custom error page.

like image 123
Kevin Johnson Avatar answered Dec 01 '25 00:12

Kevin Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!