user1855277
user1855277

Reputation: 31

mod_rewrite failing on uppercase dir

I have a very basic mod_rewrite in a .htaccess file which I'm sure worked last time I looked at it, but now it is doing strange things with the case of the REQUEST_URI. It's intended purpose is to rewrite sub-domains to a given file, passing the subdomain as a php var of bnurl. Here is my code:

RewriteCond %{REQUEST_URI}= "RSDEV/location/" [NC]  
RewriteCond %{HTTP_HOST} .  
RewriteCond %{HTTP_HOST} !^www\. [NC]  
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.co\.uk(:80)? [NC]  
RewriteRule ^RSDEV/location/$ RSDEV/newmain.php?bnurl=%1&accesstype=new [NC,L]  

Now, typing joebloggs.mydomain.co.uk/RSDEV/location/ into my web browser comes back with the response "The requested URL /RSDEV/location/ was not found on this server" which is a correct statement because /RSDEV/location/ is not a real directory, but why did it not rewrite to RSDEV/newmain.php?bnurl=joebloggs&accesstype=new as expected?

Now, the really strange thing here is that if I enter joebloggs.mydomain.co.uk/rsdev/location/ into my browser (note rsdev is now lowercase), it correctly rewrites as expected. The script newmain.php is in dir RSDEV (uppercase) so if it was going to fail, I would have expected it to fail the other way round with the lowercase rsdev.

As you can see, I have [NC] on each line. Is this my mod_rewrite code failing or some other mystical server force keeping me up all night?

Upvotes: 3

Views: 89

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

Get rid of the line:

RewriteCond %{REQUEST_URI}= "RSDEV/location/" [NC]  

The check is already being made in the rewrite rule's pattern. Not just that, the = is connected to the %{REQUEST_URI} variable, so the string ends up with a = at the end (it should really be next to the pattern).

Upvotes: 1

Related Questions