Redirect 404 Error Page Php
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business how to redirect 404 error page to homepage in php Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation how to set 404 error page in php Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just
Redirect To 404 Page Htaccess
like you, helping each other. Join them; it only takes a minute: Sign up Redirect to 404 page or display 404 message? up vote 5 down vote favorite 2 I am using a cms, and file-not-found errors can
Php Send 404 Header
be handled in different ways: The page will not be redirected, but an error-msg will be displayed as content (using the default layout with menu/footer). The page will be redirected to error.php (the page looks the same like 1. but the address changed) The page will be redirected to an existing page, e.g. sitemap.php Is there a method to be preferred in regards to search engines, or does this make no difference? php content-management-system seo if page not found redirect to homepage htaccess search-engine share|improve this question edited May 31 '11 at 14:36 Lightness Races in Orbit 218k36338587 asked May 31 '11 at 14:32 Ilyssis 1,69151625 Does the system keep a journal of the history of that URL and would therefore know what the current correct URL is? If so, then just do an internal re-direct and present the current content. Otherwise you should deliver the 404 error ( that's what its for ). –user212102 Jun 1 '11 at 7:07 add a comment| 2 Answers 2 active oldest votes up vote 10 down vote accepted If it's not found, then you should issue a 404 page. Doing a redirect causes a 302 code, followed by a '200 OK', implying that there IS some content. A 404 flat out says "there is no file. stop bugging me". Something like this would present a 404 page with proper header code:
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about
How To Redirect 404 Error Page To Homepage In Html
Stack Overflow the company Business Learn more about hiring developers or posting ads with htaccess 404 page us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is php header 404 redirect a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How can I create an error 404 in PHP? up vote 26 down vote http://stackoverflow.com/questions/6189169/redirect-to-404-page-or-display-404-message favorite 6 My .htaccess redirects all requests to /word_here to /page.php?name=word_here. The PHP script then checks if the requested page is in its array of pages. If not, how can I simulate an error 404? I tried this, but it didn't work: header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); Am I right in thinking that it's wrong to redirect to my error 404 page? php redirect http-status-code-404 share|improve this question edited May 9 http://stackoverflow.com/questions/1381123/how-can-i-create-an-error-404-in-php '10 at 21:27 Gumbo 396k64550668 asked Sep 4 '09 at 19:29 Eric 51.6k24114226 Why do you mean it doesn’t work? Did you check the server response header? –Gumbo Sep 4 '09 at 19:32 1 In answer to your concluding question, yes, it would be a bad idea to redirect all 404s to a real page. This violates the HTTP spec by turning something that shouldn't be there into something that is there. –Lucas Oman Sep 4 '09 at 19:41 add a comment| 4 Answers 4 active oldest votes up vote 50 down vote accepted What you're doing will work, and the browser will receive a 404 code. What it won't do is display the "not found" page that you might be expecting, e.g.: Not Found The requested URL /test.php was not found on this server. That's because the web server doesn't send that page when PHP returns a 404 code (at least Apache doesn't). PHP is responsible for sending all its own output. So if you want a similar page, you'll have to send the HTML yourself, e.g.: You could configure Apache to use the same page for its own 404 messages, by putting this in
404 Error Pages and Redirects for SEOs Introduction A 404 error means "not found". This is usually the page you get when you make a mistake spelling page name in a site, or if the page is deleted or moved. The problem is that the standard 404 page http://www.mcanerin.com/en/articles/301-redirect-404-error.asp is ugly and unhelpful. Many people have figured out that if you use a custom 404 page you can present a much more helpful page to you visitors. Others have taken it a step further and made that custom page a redirect https://codex.wordpress.org/Creating_an_Error_404_Page to the home page, so that any links (and PR) pointing to pages that have been deleted (or misspelled) will be passed on to the website. Sounds great, right? Well, there is a problem (there is almost always a problem with things 404 error that sound too good to be true...). The problem is that if you use a redirect to pass PR from an error page to a normal page, the redirecting page will usually return a "200 OK" or 302 Redirect code, rather than a proper 404. This messes up search engines and can result in a whole bunch of indexed URL's all looking to the search engine like duplicates of your home page (there is no redirect code, it's a pure 200 OK). "410 Gone" Error 404 error page - It's Gone, Dammit! If you are really, really insistent on a page being removed, you can send a "410 Gone" error for the location, which means that the page is not there, will never be there, and there is no forwarding address. This usually isn't necessary, but can be useful if you are trying to remove all traces of a page you no longer want associated with your site (i.e. one you were sued over, for example). It says that the page is missing on purpose, and is not an accident or temporary problem. In this case a URL removal Request to Google followed by a 410 on the page location itself should do it. You can also use robots.txt and robots metatag as backup. This is bad for your site. Additionally, there are a LOT of indexed "error" pages in search engines (especially Yahoo) that should not be there. The proper behaviour for an error page is to return a 404 error code. The best result for your visitors is an error page that is either helpful by itself or redirects to a helpful page. The best result from an SEO viewpoint is for any link popularity for broken links be passed on to the page of your choice. Naturally, the best result overall would be something that accomplishes all of the above. Unfortunately, this is not directly possible. As soon as the search engine is sent the error code, it treats it as a dead page and will eventually re
the new WordPress Code Reference! Creating an Error 404 Page Languages: English • 日本語 • (Add your language) While you work hard to make sure that every link actually goes to a specific web page on your site, there is always a chance that a link clicked will slam dunk and become a famous 404 ERROR PAGE NOT FOUND. All is not lost. If your visitors encounter an error, why not be a helpful WordPress site administrator and present them with a message more useful than "NOT FOUND". This lesson will teach you how to edit your "error" and "page not found" messages so they are more helpful to your visitors. We'll also show how to ensure your web server displays your helpful custom messages. Finally, we'll go over how to create a custom error page consistent with your Theme's style. Contents 1 An Ounce of Prevention 2 Understanding Web Error Handling 3 Editing an Error 404 Page 4 Creating an Error 404 Page 5 Tips for Error Pages 5.1 Writing Friendly Messages 5.2 Add Useful Links 6 Testing 404 Error Messages 7 Help Your Server Find the 404 Page 8 Questions About Error Files An Ounce of Prevention Some errors are avoidable, you should regularly check and double check all your links. Also, if you are deleting a popular but out-of-date post, consider deleting the body of the post, and replacing it with a link referring visitors to the new page. Understanding Web Error Handling Visitors encounter errors at even the best websites. As site administrator, you may delete out-of-date posts, but another website may have a link to your inside page for that post. When a user clicks on a link to a missing page, the web server will send the user an error message such as 404 Not Found. Unless your webmaster has already written custom error messages, the standard message will be in plain text and that leaves the users feeling a bit lost. Most users are quite capable of hitting the back key, but then you've lost a visitor who may not care to waste their time hunting for the information. So as not to lose that visitor, at the very least, you'll want your custom message to provide a link to your home page. The friendly way to handle errors is to acknowledge the error and help them find their way. This involves creating a custom Error Page or editing the one that came with your WordPress Theme. Editing an Error 404 Page Every theme that is shipped with WordPress has a 404.php file, but not all Themes have their own custom 404 error template file. If they do, it will be named 404.php. WordPress will automatically use that page if a Page Not Found error occurs. The normal 404.php page shipped with your Theme will work, but does it say what you want it