Link to home
Start Free TrialLog in
Avatar of MaybeItsJeremy
MaybeItsJeremy

asked on

ReWrite Rule for everything except specific directories

Here is my current .htaccess file:

Options +Indexes
Options +FollowSymlinks
RewriteEngine on

RewriteRule ^favicon.ico - [L]
RewriteRule ^images - [L]
RewriteRule ^design/images - [L]
RewriteRule ^design/style - [L]

RewriteRule ^(.*)$ index.php [QSA,L]


Every address is rewritten to my index.php file except the specific direcotires listed... Now I need to add something to it. I am going to have a directory for each state in the USA. (CA, NC, FL... etc...). I need to have a rewrite rule that only matches letters, and is limited to 2 characters. I have tried one example to no avail:

RewriteRule ^([a-zA-Z]{2})/? - [L]

Of course, that has to come before my index.php rewrite rule...And keep in mind, the ending slash is optional, someone may directly type in the address and omit the end slash, I need to cater to that.

Any help is appreciated.
Avatar of david_levine
david_levine

What are you looking for http://www.yoursite.com/CA to redirect to?

RewriteRule ^[a-zA-Z]{2})$ /$1/ [R]
RewriteRule ^([a-zA-Z]{2})/? xxxxxxxxxxxx [L]

The above might be what you need if you can post what you are redirecting to, unless I missed it above.
Avatar of MaybeItsJeremy

ASKER

I don't want it to redirect to anything, I just want it to have a last rule, so it will not be directed to the index.php file. Basically yoursite.com/CA needs to actually go to yoursite.com/CA instead of yoursite.com/index.php.
ASKER CERTIFIED SOLUTION
Avatar of david_levine
david_levine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You got me on the right path! Thank you.

The end result that works for me is:

RewriteRule ^([a-zA-Z]{2})/?(.*)$ - [L]