Force 404 Error
Contents |
that will work. get httpfox for firefox and you can check the return codes. Zaggs 2008-12-04 php throw 404 exception 21:51:53 UTC #3 galen said: that will work. get httpfox for firefox
Php Send 404 Header
and you can check the return codes. Ok, but it's not forcing a redirect to the 404 php redirect to 404 page page, any ideas? Zaggs 2008-12-05 10:57:38 UTC #4 still struggling with this? would greatly appreciate any help... Stormrider 2008-12-05 11:02:32 UTC #5 All it does its return the status php 404 page code, it doesn't force a redirect to any 404 page or anything. You have to do that yourself. Zaggs 2008-12-05 11:09:48 UTC #6 Stormrider said: All it does its return the status code, it doesn't force a redirect to any 404 page or anything. You have to do that yourself. How would I redirect to 404.shtml? Stormrider 2008-12-05 11:20:41
Php Return 404 Status Code
UTC #7 Best way is probably just to include() it after sending the status code, then exit(). galen 2008-12-05 16:12:18 UTC #8 try ErrorDocument 404 /notfound.html in .htaccess Stormrider 2008-12-05 18:00:47 UTC #9 That will work for apache generated 404 errors. For ones you throw in php, you will need to output the page yourself. felgall 2008-12-05 18:30:39 UTC #10 The easiest way would be: header("Location: dkjlflkjxfgkdnbcxfn.html"); As long as you don't actually have a page with that filename. Stormrider 2008-12-05 22:45:49 UTC #11 Then there is little point in outputting the 404 header, since that would generate the error anyway. Would look a bit rubbish though. imaginethis 2008-12-05 23:09:43 UTC #12 Did you try header("HTTP/1.0 404 Not Found"); echo "
404 File not found
"; ? er... ignore me... I'm half reading... half working >.> you can also try header("Status: 404 Not Found"); echo "404 File not found
"; system 2014-10-08 00:47:58 UTC #13 Home Categories FAQ/Guidelines Terms of Service Privacy Policy Powered by Discourse, best viewed with JavaScript enabled Shop Versioning Reference Articles Premiumhere 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 developers or posting ads php 404 not found with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the php header 404 redirect Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:
Php Throw 404 Error
Sign up Force 404 with PHP and .htaccess not working up vote 10 down vote favorite 2 I am attempting to throw my own 404 in PHP depending on certain GET vars. But the following is not working. I can confirm https://www.sitepoint.com/community/t/php-force-404-error/4490 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 23 '11 at 16:12 wilsonpage 7,9371278135 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? http://stackoverflow.com/questions/7164144/force-404-with-php-and-htaccess-not-working –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 comment 2 Answers 2 active oldest votes up vote 10 down vote accepted As far as Apache's concerned, it's done its job as it has properly found the page/script that the user's request called for. The fact that the script is outputting a 404 header is irrelevant to Apache, since its job was completed properly. You'd need to have your PHP script output the 404 header, and inc
tour help Tour Start 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 http://wordpress.stackexchange.com/questions/91900/how-to-force-a-404-on-wordpress about hiring developers or posting ads with us WordPress Development Questions Tags Users Badges Unanswered Ask Question _ WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes https://sites.google.com/site/onlyvalidation/page/force-a-404-or-410-using-the-htaccess-file-on-apache-server a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to force a 404 on WordPress up vote 21 down 404 error vote favorite 6 I need to force a 404 on some posts based on conditions. I managed to do it ( although I don't know if I did it the right way) and I'm a getting my 404.php template to load as expected. My code: function rr_404_my_event() { global $post; if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) { include( get_query_template( '404' ) ); exit; # so that the normal page isn't loaded after the php throw 404 404 page } } add_action( 'template_redirect', 'rr_404_my_event', 1 ); Code 2 from this related question - same problem: function rr_404_my_event() { global $post; if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) { global $wp_query; $wp_query->set_404(); } } add_action( 'wp', 'rr_404_my_event' ); My Issue: Although it looks good, I get a status 200 OK if I check the network tab. Since it's a status 200, I am afraid that search engines might index those pages too. Expected Behaviour: I want a status 404 Not Found to be sent. redirect 404-error share|improve this question edited Mar 22 '13 at 9:43 asked Mar 22 '13 at 6:53 RRikesh 3,41641534 From the related questions: wordpress.stackexchange.com/questions/73738/… – did you read that? –toscho♦ Mar 22 '13 at 9:34 Yes, I still get a status 200 with that. –RRikesh Mar 22 '13 at 9:40 add a comment| 5 Answers 5 active oldest votes up vote 19 down vote accepted +150 You could try the Wordpress function status_header() to add the HTTP/1.1 404 Not Found header; So your Code 2 example would be: function rr_404_my_event() { global $post; if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) { global $wp_query; $wp_query->set_404(); status_header(404); } } add_action( 'wp', 'rr_404_my_event' ); This function is for example used in this part: function handle_404() { ...cut... // Guess it's time to 404. $wp_query->set_404(); status_header( 404
module enabled, using the .htaccess file. Add these directives (adjusted for your particular situation): RewriteEngine on ## list uris which are supposed to return 404 are rewritten to a non-existent url which returns a 404 anyway - the server is supposed to respond with a 404** RewriteRule ^(.*)/path-to/url-of-bad-page-i-want-to-see-gone-forever\.html$ http://www.example.com/nonexistent-file-which-gives-404.php ## list uris which are supposed to return 410 RewriteRule ^(.*)/path-to/url-of-bad-page-i-want-to-see-gone-forever\.html$ - [G] ## custom error documents - note that you use only their uri - relative to the root (/) - NEVER use the fully qualified url with http://www.exampe.com/ part. ErrorDocument 404 /error-404.php ErrorDocument 410 /error-410.php **In cases when the server does not respond with a 404 naturally for a non-existent file, then make a php script called nonexistent-file-which-gives-404.php containing this code in it: Even though the file exists, it responds with a 404 - so as far as the server is concerned and any user agent checking the response, it does not exist. How to force a 404 or 410 for a url containing a query string you don't want to allow This is similar to how we strip off a query string except we serve a custom 404 (or 410) error page and respond with a 404 (or 410). Useful for sites that have been hacked (and subsequently unhacked) when you want to ensure all the spammy urls formed with various query strings that your site otherwise doesn't use and created during the hack will respond with 404 or 410. In this example there are 3 query string parameters parm1 through parm3 that may be used together in any order in a query string which make it an undesirable url. We want to respond with 40