Php Trigger 404 Error
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 php return 404 error Overflow the company Business Learn more about hiring developers or posting ads with us Stack php force 404 error Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community php redirect to 404 page of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Force 404 with PHP and .htaccess not working up vote 10 down vote favorite 2 I am
Php Return 400
attempting to throw my own 404 in PHP depending on certain GET vars. But the following is not working. I can confirm that the pge header is coming back with a '404 status code' though. .htaccess just doesn't seem to be redirecting correctly. Am I missing something? PHP Code: if(!$_GET['page']){ header('HTTP/1.0 404 Not Found'); } .htaccess Code: ErrorDocument 404 /404.html Many thanks! php .htaccess redirect http-status-code-404 share|improve this question asked Aug php throw 404 exception 23 '11 at 16:12 wilsonpage 7,9471278135 2 I'm guessing Apache doesn't throw a 404 error since the page actually does exist. Maybe you should add a redirect to the 404 page in php? –Andre Backlund Aug 23 '11 at 16:15 2 Don't redirect to a 404 error page, that'll turn it into a 200 request. Just have PHP include the error page's contents. –Marc B Aug 23 '11 at 16:16 @Marc But he's already responding with a 404 status code, he shouldn't have to remove that part. –Andre Backlund Aug 23 '11 at 16:18 1 @Andre yes, but to do a redirect, it'd have to be a 301 error code. You can't output 404 not found + 301 go elsewhere. Apache doesn't do a redirect to serve up a 404 page. It's just an internal rewrite that dumps out the contents of the specified 404 page, WITHOUT ever doing a redirect. –Marc B Aug 23 '11 at 16:20 If the page exists and is visible to the web, then a 404 is inappropriate. Since you are checking values and throwing an error if the value(s) are inappropriate, a 412 Precondition Failed error might be better. –dnagirl Aug 23 '11 at 16:22 | show 1 more
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 php 404 page Stack Overflow the company Business Learn more about hiring developers or posting ads with
Php Header 404 Redirect
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a
Header("http/1.0 404 Not Found");
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 favorite http://stackoverflow.com/questions/7164144/force-404-with-php-and-htaccess-not-working 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 '10 http://stackoverflow.com/questions/1381123/how-can-i-create-an-error-404-in-php at 21:27 Gumbo 396k64548668 asked Sep 4 '09 at 19:29 Eric 51.4k24114226 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 httpd.conf: ErrorDocument 4
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 http://stackoverflow.com/questions/437256/why-wont-my-php-app-send-a-404-error hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask 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 up Why won't my PHP app send a 404 error? up vote 135 down vote favorite 24 if (strstr($_SERVER['REQUEST_URI'],'index.php')) { header('HTTP/1.0 404 Not Found'); } Why wont this work? I get 404 error a blank page. php header http-status-code-404 share|improve this question edited Jan 11 '14 at 23:29 danorton 6,31932644 asked Jan 12 '09 at 22:26 Yrrol 1 Better option would be to send a 404 status and include your custom 404 page immediately. That's what i used to do. –Rocky Oct 25 '12 at 7:05 On my PHP server it works perfectly. The above line returns the server's default 404 page. I suppose that this can be configured php trigger 404 in the server. –Elmue Oct 7 '14 at 23:25 add a comment| 16 Answers 16 active oldest votes up vote 297 down vote Your code is technically correct. If you looked at the headers of that blank page, you'd see a 404 header, and other computers/programs would be able to correctly identify the response as file not found. Of course, your users are still SOL. Normally, 404s are handled by the web server. User: Hey, do you have anything for me at this URI webserver? Webserver: No, I don't, 404! Here's a page to display for 404s. The problem is, once the web server starts processing the PHP page, it's already passed the point where it would handle a 404 User: Hey, do you have anything for me at this URI webserver? Webserver: Yes, I do, it's a PHP page. It'll tell you what the response code is PHP: Hey, OMG 404!!!!!!! Webserver: Well crap, the 404 page people have already gone home, so I'll just send along whatever PHP gave me In addition to providing a 404 header, PHP is now responsible for outputting the actual 404 page. share|improve this answer answered Jan 13 '09 at 1:39 Alan Storm 114k63280429 8 Any reason to care? –Pim Jager Feb 22 '09 at 15:30 48 14 year old girl or not, the little cheesy dialog really made this make sense to