Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Help

mod rewrites

         

lostdog

12:06 am on Apr 23, 2008 (gmt 0)

10+ Year Member



I am trying to do a mod rewrite for all 50 States.

(e.g. [mydomain.com...]

rewritten to: (e.g. [mydomain.com...]

How would I do this for all 50 States with one rule?
the only difference in the url is the state abrevation.

Can it be done?

I have been trying for hours but dont have a clue!

Thanks in advance.

g1smd

11:21 am on Apr 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can't be done in one rule, because Mod_Rewrite has no way to "translate" from "md" to "maryland".

jdMorgan

2:38 pm on Apr 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, there is a way to handle "closed map" problems like this, where all mappings can be enumerated. It is, however, somewhat inefficient with long lists:

RewriteCond $1>de ^delaware>(.+)$ [OR]
RewriteCond $1>md ^maryland>(.+)$ [OR]
RewriteCond $1>ny ^new-york>(.+)$ [OR]
RewriteCond $1>pa ^pennsylvania>(.+)$ [OR]
RewriteCond $1>va ^virginia>(.+)$ [OR]
...
RewriteCond $1>wy ^wyoming>(.+)$
RewriteRule ^inspectors/([^.]+)\.html$ /inspectors/inspectors.php?st=%1 [L]

I suggest ordering the RewriteConds from most- to least-requested states, depending on your traffic.

The ">" character doesn't really do anything, except to visually-delimit the two variables in each RewriteCond. I use it because it implies concatenation, but it is not treated as an operator by the regular-expressions parser.

Note that there must not be an [OR] flag on the final RewriteCond.

Jim