Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule Too Long?

Is having these many conditionals too intensive?

         

curlybill09

7:48 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



I am using mod_rewrite to rewrite some URL's for a database application. One of my URL's I am rewriting must start (after the base folder) with a folder named after one of the 50 U.S. states (ie. /alabama/, /alaska/, /arizona/, and so on.).

Is it okay to include all 50 of these state names within my RegEx pattern conditional? Or is that way too much info to put into a pattern and be too intensive?

Example:

^/?(alabama地laska地rizona地rkansas圭alifornia圭olorado圭onnecticut圬elaware圩lorida
夙eorgia多awaii夷daho夷llinois夷ndiana夷owa妄ansas妄entucky奸ouisiana妃aine妃aryland
妃assachussets妃ichigan妃innesota妃ississippi妃issouri妃ontana好ebraska好evade
好ew-hampshire好ew-mexico好ew-york好orth-carolina好orth-dakota她hio她klahoma她regon
如ennsylvania字hode-island存outh-carolina存outh-dakota宇ennesee宇exas守tah宅ermont
宅irginia安ashington安est-virigina安isconsin安yoming)/([a-zA-Z_]+)/([a-zA-Z_]+)$

[edited by: jdMorgan at 5:38 pm (utc) on Feb. 12, 2007]
[edit reason] Fixed side-scroll [/edit]

wilderness

12:44 am on Feb 12, 2007 (gmt 0)

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



Seem to recall an old suggestion that these be kept down to 5-6 OR's.

Unfortuantely I'm unable to convey the reason.
Whether it's server load or speed in application of rules?
Perhaps one of Apache geeks may provide the reason.

jdMorgan

5:41 pm on Feb 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it works, it works... And, in simple terms, if this is what you need, then this is what you should use.

The only reason to shorten that pattern (by breaking it into multiple [OR]ed RewriteConds, for example) would be to make maintenance easier. But if this list is not likely to change often, then there's no reason to do that.

If you had 100 rules like this, then I'd start to worry a little about performance...

Jim

wilderness

8:20 pm on Feb 12, 2007 (gmt 0)

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



Many thanks Mr. Geek ;)