My rule does not like lowercase....

Oh, the strange things mod_rewrite does!

My rule does not like lowercase....

Postby nico80 » Mon Feb 11, 2008 4:07 am

I have a really weird problem.

I'm using this rule:
Code: Select all
RewriteRule ^(.*)/$ index.php?s=$1 [L]

To redirect:
/section/subsection/
to
index.php?s=section/subsection

index.php then checks the variable s against a DB of entries and includes a different page depending on the section.
In the DB I store the sections all in lowercase and I compare them using LCASE in the SQL query, so that
/section/
/Section/
/SeCtIoN/
all direct to the same page

Now.... everything seems to work perfectly! Well, almost everything.

Specifically, if I write
/Section/
/SEction/
/seCtion/
/secTIOn/
and so on, it always works but if I write
/section/

it does not work... I get a 404 server error (URL /section/ not found)

This applies ONLY to the section names I have in the DB.... it's not just a lowercase thing. If I write:
/sectionwhichdoesnotexist/
the server shows index.php, that then gives the error (this page does not exist).

Now my question is: how on Earth is this possible?? Am I missing something really obvious?
If I change the code in index.php just to:
Code: Select all
die("blablabla");

so that it doesn't even get to the point when it reads the DB, it still doesn't work.

Is mod_rewriting decided that it automatically has to read my database without me asking for it? Or what?

Oh, I was almost forgetting! Obviously all of this works without a problem locally on my laptop...
nico80
 
Posts: 3
Joined: Mon Feb 11, 2008 3:45 am
Location: Dunedin, New Zealand

problem found (not solved yet...)

Postby nico80 » Mon Feb 11, 2008 1:30 pm

Ok, I knew a good night of sleep would have helped. I actually found what the problem is!
The DB is not involved in all of this, as expected. The fact is that in my directory I have some php files with the same name as the sections (es. section news -> news.php).

mod_rewrite seems to be annoyed by that, so if I go to

/news/

he gives me a 404 because a news.php file exists... but if I go to

/News/

he redirects me to index.php because no News.php file exists!
If I change news.php into News.php the situation is the other way around.

OK, so I figured out the problem... anyone could help me in figuring out a way around it?

Thank you a lot
nico
nico80
 
Posts: 3
Joined: Mon Feb 11, 2008 3:45 am
Location: Dunedin, New Zealand

Postby richardk » Mon Feb 11, 2008 4:35 pm

The problem is MultiViews, try
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*[^/])/?$ /index.php?s=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby nico80 » Mon Feb 11, 2008 10:25 pm

Thank you very much for your reply!
Unfortunately the server that hosts my site does not seem to like the MultiViews line you suggested.
If I put it it just gives me a 500 internal server error.

I think the easiest solution is to put all of the culprit files in a separate directory, so I won't run in any name conflict problems.

Thank you very much
nico
nico80
 
Posts: 3
Joined: Mon Feb 11, 2008 3:45 am
Location: Dunedin, New Zealand


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 2 guests

cron