Handling 404 Error In 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 Learn more about hiring custom 404 error page developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question custom 404 page examples x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; 404 error page template it only takes a minute: Sign up Best way to handle 404 error with redirect to homepage up vote 1 down vote favorite I've searched, read a lot, but still couldn't find a way, to achieve my goal. Now I 404 error page html code even think it is impossible. Is it? I want 404 errors to handled properly so I have ErrorDocument 404 /404.php in the .htaccess file, and I want to send out the right header to search engines header("HTTP/1.1 404 Not Found") to forget that page, also I want to redirect my visitor to /index.php?code=404 so I can inform him about that what he was looking for is not available, but still keep him on the site. Now it seems everything
How To Create 404 Error Page In Php
is fine, until I want to redirect the user: then the server sends out a 302 message, which overwrites my previous 404 header, so while I can send the user to the desired place, I still can't tell the searchbots that the address is wrong. If I add a include("index.php?code=404") after the header line it just won't work, the server says that file does not exist. What should I do? php html apache share|improve this question asked Jul 16 '12 at 9:54 ZTefter 8419 I've forgot to mention: as I searched on the topic, it raised an interesting question: what if my index.php?code=404 page has something missing, like an icon for example. While my site generates the page, the icon will give a 404, which will redirect, which will generate a 404... so isn't there a chance that my original idea will generate some infinite loop? –ZTefter Jul 16 '12 at 10:11 add a comment| 3 Answers 3 active oldest votes up vote 5 down vote accepted Try something like this: