February 21st, 2011, 09:34 PM
Redirection problem: how do I map Ids ?
I'm new with mod_rewrite and I'm having a problem.
I need to redirect
The question is: how could I map 275 to Italy ?
ps: I'm using mod_rewrite.
February 21st, 2011, 09:45 PM
mod_rewrite is only the first part. You can get the value "Italy" to a script, and the script determines the country number.
So say guides.foo is the script you have now. It takes the "country" from the URL. Make it also take the country name (however you decide to do that), then use URL rewriting to turn /guides/XYZ into /guides?whatever=XYZ.
Apache can do that specific URL right out of the box, as long as /guides is an actual file (like guides.php). With
/guides/Italy will automatically go to /guides.php. To get to it you look at the CGI PATH_INFO value, which will have "/Italy". Remove the slash, look up the ID corresponding to the county, and you're done. (Or just use different SQL queries or whatever that look at the county name instead of its ID.)
If you need help with the script, be sure to mention what language its uses: PHP, Python, Perl, etc.
February 21st, 2011, 10:17 PM
I don't follow you
I'm using rails, but I would like to solve this at server level.
How do I look at CGI PATH_INFO value ?
I think that maybe RewriteMap could be a solution, don't you agree?
February 21st, 2011, 10:46 PM
RewriteMap could work but is often harder to set up than the simple RewriteRule version.
I'm sure Rails eats this kind of stuff for breakfast. Moving...