Jump to content

RewriteRule Too Long?


seodevhead

Recommended Posts

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|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachussets|michigan|minnesota|mississippi|missouri|montana|nebraska|nevade|new-hampshire|new-mexico|new-york|north-carolina|north-dakota|ohio|oklahoma|oregon|pennsylvania|rhode-island|south-carolina|south-dakota|tennesee|texas|utah|vermont|virginia|washington|west-virigina|wisconsin|wyoming)/([a-zA-Z_]+)/([a-zA-Z_]+)$

 

 

Link to comment
Share on other sites

That amount of alternation is not ideal at all. Can you use their abbreviations? If you must use the names, you should be able to condense the pattern a little, but it would still be a lot of work. For instance, (alabama|alaska) can be reduced to (ala(?:bama|ska)), which will prevent backtracking and reanalyzing 3 characters.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.