Forum Moderators: phranque
selectedCity=united kingdom
or
selectedCity=germany
In preparing my site to use mod_rewrite with friendly urls, I have added hyphens to those variables that are more than one word:
selectedCity=united-kingdom
or
selectedCity=czech-republic
Is there a rule to make sure that the hyphen isn't parsed along with my real variable (united kingdom)
My rewrite code follows:
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]
Thanks,
Gordon
I don't understand that question, and I suspect it is because you believe that mod_rewrite is smarter than it really is. Your script replaces spaces with hyphens in URLs on your pages, and converts them to "spider-friendly" format. Browsers and 'bots request those URLs. When a request arrives at your server, mod_rewrite converts the parameters in the URL to query string format and calls your script. Your script should then convert the hyphens back to spaces and look up the city or country in your database. This hyphen-to-space conversion can be done easily in php with preg_replace:
$spaced_city = preg_replace('/-/',' ',$hyphenated_city);
part of my confusion comes from the fact that for some reason my variables with hyphens aren't being passed to the correct page -
if I type in /destinations/spain
there isn't a problem.
If I type in /destinations/czech-republic
Tit doesnt work.
If, however, I go directly to the page mod_rewrite is parsing to:
/articles.php?selectedCity=czech-republic
it works... I have tried echoing the variable in the session file which is the very first thing that is processed on articles.php, and any hyphenated variables don't even echo, which I find very bizzare.
In order to see what the mod_rewrite output looks like, you can change your rule(s) (temporarily) to an external redirect. This will make the rewritten URL show in your browser address bar, which may help you diagnose the problem.
RewriteRule ^destinations/([^/]*)/([^/]*)/([0-9]*)\.html$ http://www.example.com/read.php?theCountry=$1&theCity=$2&aid=$3 [R=301,L]