Jump to content

Recommended Posts

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

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]

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.

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!

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.