Dragen Posted October 30, 2009 Share Posted October 30, 2009 Hi, I'm using mod-rewrite to change all urls like this: mydomain.co.uk/thispage/ to this: mydomain.co.uk/thispage.php Which is working perfectly, but it's stopped any 404 erros from displaying correctly. If I try and access a non-existent .html file it works fine, but when I access a 'folder' (i.e; mydomain/nofile/) file which doesn't exist it simply brings up a blank screen and returns a header of: HTTP/0.9 200 OK Although trying to access a non-existent .php file directly (i.e; mydomain/nofile.php) causes firefox to try and download a blank php file. If I remove the re-write code from my .htaccess file it works, so I'm putting it down to apache re-writing the url so it skips the file not found error check..? The code is as follows: RewriteRule ^([a-z0-9]*)/$ $1.php [NC] If anyone can help it would be greatly appreciated! I've just spent the last couple of hours trying to find a solution. Regards, Lee Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/ Share on other sites More sharing options...
corbin Posted October 31, 2009 Share Posted October 31, 2009 Is that your entire rewrite rule? Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/#findComment-948185 Share on other sites More sharing options...
Dragen Posted October 31, 2009 Author Share Posted October 31, 2009 No, but it's the only part that seems to be effecting the 404 page. Here's the rest, although I've removed a few bits that have no relevance: ErrorDocument 404 /errors/404.php RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\. [NC,OR] RewriteCond %{HTTP_HOST} daisymoondesign.co.uk [NC,OR] RewriteCond %{HTTP_HOST} daisymoondesigns.com [NC] RewriteRule (.*) http://daisymoondesigns.co.uk/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^maillist(/([a-z\-\ ]+)/?)$ maillist.php?action=$2&%{QUERY_STRING} [NC] RewriteRule ^policies(/([a-z\-\ ]+)/?)$ policies.php?policy=$2&%{QUERY_STRING} [NC] RewriteRule ^([a-z0-9]+)$ $1/ [R,NC] RewriteRule ^([a-z0-9]+)/$ $1.php [NC] RewriteRule ^register/([a-z\-\ ]+)/?$ register.php?action=$1&%{QUERY_STRING} [NC] RewriteRule ^basket/([a-z\-\ ]+)/?$ basket.php?action=$1&%{QUERY_STRING} [NC] RewriteRule ^checkout/([a-z\-\ ]+)/?$ checkout.php?action=$1&%{QUERY_STRING} [NC] RewriteRule ^thumbs/(([a-z0-9\_\ /]+)/)?(([0-9]+)-([0-9]+))/(([a-z0-9\_]+)\.(jpg|gif|png))$ incs/thumbs.php?dir=$2&width=$4&height=$5&img=$6 [NC] RewriteRule ^images/?(([0-9]+)-([0-9]+))/captcha\.(jpg|gif|png)$ incs/captcha.php?getimage=true&width=$2&height=$3 [NC] RewriteRule ^store/([a-z0-9\&\-\/\_\ ]+)+(/(.+?).itm)?$ index.php?c=$1&i=$3&%{QUERY_STRING} [NC,L] Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/#findComment-948295 Share on other sites More sharing options...
Dragen Posted November 3, 2009 Author Share Posted November 3, 2009 Does nobody have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/#findComment-950178 Share on other sites More sharing options...
corbin Posted November 3, 2009 Share Posted November 3, 2009 The first thing I notice is: RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d Two things: -That only applies to one rewrite rule. RewriteConds only apply to the closest following RewriteRule. (Maybe that's on purpose though.) -The OR will always make it true, since something can't be both a file and a directory. If file does not exists or directory does not exist. So that RewriteCond is basically useless. Perhaps you meant it without the OR? Oddly enough the only rule that would apply to /directory/ would be: RewriteRule ^([a-z0-9]+)/$ $1.php [NC] And then no rules after that would apply any more as far as I can tell. The weird part is that that should still give an error if whatever.php does not exist. What version of PHP is it? And if you remove just that 1 line does it work? Also, your RewriteRules could be optimized a bit. Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/#findComment-950561 Share on other sites More sharing options...
Dragen Posted November 3, 2009 Author Share Posted November 3, 2009 Thanks for the response. The [OR] bit was actually put in recently whilst I was just throwing about random code to get it to work.. so I'll remove that. And yes, my code probably could be optimised a lot. I'm not brilliant at htaccess though, but if yuo have any tips they'll be more than welcome! Yes, if I remove the line: RewriteRule ^([a-z0-9]+)/$ $1.php [NC] It sees to work fine, so I put it down to something like apache doesn't pick up the 404 because of the rewrite.. I don't know. Also, if I try and access a non-existent .php file with the filetype, like this: mydomain.co.uk/nofile.php then the rewrite doesn't come into it, but it tries to download the .php file. If you download it the content is blank. Yet another strange happening! Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/#findComment-950571 Share on other sites More sharing options...
Dragen Posted November 15, 2009 Author Share Posted November 15, 2009 I'm still looking for a solutio to this problem, if anyone has any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/179687-re-write-to-non-existent-php-doesnt-throw-404-error/#findComment-957932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.