Php Code To Redirect 404 Error Page
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
How To Redirect 404 Error Page In Php
this site About Us Learn more about Stack Overflow the company Business php 404 redirect htaccess Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask
How To Create 404 Error Page In Php
Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign how to redirect 404 error page to homepage in php up PHP - Display a 404 Error without redirecting to another page up vote 8 down vote favorite 5 I want to display a 404 Error if a user reaches a page that exists but I don't want him/her to see. I don't want to do redirect (that would cause the address bar to show the link of the error page in the custom 404 page examples address bar) like the following: if ($this_page_should_not_be_seen) header("Location: err.php?e=404"); Instead, it should seem like the page really doesn't exist, without having the URL in the browser's address changed. php custom-error-pages share|improve this question edited May 31 '15 at 8:29 asked Jun 21 '12 at 11:57 Dilip Raj Baral 1,16851542 1 and what's wrong with htaccess? –k102 Jun 21 '12 at 11:58 1 That's the job for .htaccess, not for PHP file... or, for both of them, if you just redirect everything to index.php, but still, you need .htaccess or access to httpd.conf. –Griwes Jun 21 '12 at 11:59 1 you mean your browser shows the 404 error rather than a custom 404 page? you can redirect it to some page with doesn't exist in actual. –Ummar Jun 21 '12 at 11:59 @Ummar That would work, but I was wondering if there is formal way to do this.. –Dilip Raj Baral Jun 21 '12 at 12:15 1 best formal way I think is .htaccess –Ummar Jun 21 '12 at 12:20 | show 1 more comment 5 Answers 5 active oldest votes
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
How To Create 404 Error Page In Html
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges php send 404 header Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each
Php Header 404 Redirect
other. Join them; 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 http://stackoverflow.com/questions/11137625/php-display-a-404-error-without-redirecting-to-another-page my goal. Now I 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 http://stackoverflow.com/questions/11501985/best-way-to-handle-404-error-with-redirect-to-homepage the site. Now it seems everything 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: