#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0

    Redirection problem: how do I map Ids ?


    Hi,
    I'm new with mod_rewrite and I'm having a problem.
    I need to redirect
    mysite/en/guides?country=275
    to
    mysite/en/guides/Italy

    The question is: how could I map 275 to Italy ?

    ps: I'm using mod_rewrite.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,054
    Rep Power
    9398
    mod_rewrite is only the first part. You can get the value "Italy" to a script, and the script determines the country number.

    Generic solution:

    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.

    Specific solution:

    Apache can do that specific URL right out of the box, as long as /guides is an actual file (like guides.php). With
    Code:
    Options +MultiViews
    /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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    4
    Rep Power
    0
    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?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,054
    Rep Power
    9398
    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...

IMN logo majestic logo threadwatch logo seochat tools logo