Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite with variables / initial caps

Need some help with sorting out mod_rewrite and variables

         

marakkesh

5:49 am on Dec 6, 2004 (gmt 0)

10+ Year Member



My database is structured to that my page articles.php parses the variable selectedCity to my database.

selectedCity can be either a country OR a city - I use php to determine which it is, and respond appropriately.

My mod_rewrite rule turns

www.mysite.com/destinations/Madrid

into

www.mysite.com/articles.php?selectedCity=Madrid

if I use lowercase for the city, it works fine as well:

www.mysite.com/articles.php?selectedCity=madrid

The problem is when I try and use the country as lowercase:

www.mysite.com/articles.php?selectedCity=spain

my variable is not parsed by the database. Using uppercase Spain works.

Here is my code:

RewriteRule ^destinations/([a-zA-Z]*)$ /articles.php?selectedCity=$1 [L]
RewriteRule ^destinations/([a-zA-Z]*)/([a-zA-Z]*)$ /articles.php?theCountry=$1&selectedCity=$2 [L]
RewriteRule ^destinations/([a-zA-Z]*)/([a-zA-Z]*)/([0-9]*)\.html$ /read.php?theCountry=$1&theCity=$2&aid=$3 [L]

Just a note, the variables 'theCountry' and 'theCity' are dummies - they aren't actually parsed to the database...

Any help appreciated.

Gordon

jdMorgan

6:13 am on Dec 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Gordon,

Welcome to WebmasterWorld!

Since all your RewriteRules are identical in form, that's a good hint that the problem is not in mod_rewrite, but in your script. I suspect you'll find that cities are checked for case and fixed-up if needed, while countries are not. Or it could be the form of the database lookup call -- case-sensitive lookup versus case-insensitive. I'm not sure, since I don't know any of these details.

But either way, it's a lot easier to do case-conversion in PHP than in mod_rewrite! :)

Jim

marakkesh

8:19 am on Dec 6, 2004 (gmt 0)

10+ Year Member



Thanks for the tip - I was doing a php in_array search which for looking an exact case match, which it wasn't finding.

Thanks for pointing me in the right direction!