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.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You got me on the right path! Thank you.
The end result that works for me is:
RewriteRule ^([a-zA-Z]{2})/?(.*)$ - [L]
The end result that works for me is:
RewriteRule ^([a-zA-Z]{2})/?(.*)$ - [L]
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.