Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect 404 or just 404 header

I'm currently coding a site and I want to know the best alternative.

Should I add header("HTTP/1.0 404 Not Found") without redirecting or should I redirect and add a 404 header?

like image 341
BlackVoid Avatar asked Mar 14 '12 19:03

BlackVoid


People also ask

Should 404 pages redirect?

404s should not always be redirected. 404s should not be redirected globally to the home page. 404s should only be redirected to a category or parent page if that's the most relevant user experience available. It's okay to serve a 404 when the page doesn't exist anymore (crazy, I know).

How do I redirect a 404 page not found?

The select Manage on the menu on the left side of the screen, and Redirects on the menu that opens up from there. Click the Add Rule button. Enter the page you want to redirect in the box on the left. Select the type of redirect in the dropdown menu.


2 Answers

Redirecting means "What you asked for is actually over here".

If it isn't found, then it isn't found. Don't redirect.

Output a 404 status code, and then an HTML document that explains that whatever was requested wasn't found. You can then suggest an onwards journey by, for example, providing links to the main sections of the site or performing a search based on keywords extracted from the URL.

(The practical consequences of redirecting are that the URL vanishes from the address bar which makes it hard to look at an think "Oh, I mistyped that one letter, I'll just change it" or to copy/paste it into a bug report, etc).

like image 91
Quentin Avatar answered Sep 26 '22 20:09

Quentin


header("Status: 404 Not Found"); //FastCGI
include("404.php");
exit;

URI remains the user asked.

like image 24
dstonek Avatar answered Sep 22 '22 20:09

dstonek