How to Omit Matches from htaccess Regular Expression
RewriteEngine On
RewriteBase /
RewriteRule ^sample-([a-z][a-z]).php /state.php?m=$1
RewriteRule ^sample-([a-z^-]+).php /city.php?m=$1
I have two regular expressions in my htaccess file, which look for a state (two alphabetical characters, for example "sample-tx.php") and city (any su开发者_StackOverflow社区m of alphabetical characters and dashes, for example "sample-new-bedford.php").
These expressions work great right now, but I need help with two things:
For the state expression, how would I omit "az" and "tx", so when someone goes to "sample-az.php" or "sample-tx.php" they are not redirected?
Same question as #1, except this time for cities. How would I omit "houston" and "new bedford", so when someone goes to "sample-houston.php" or "sample-new-bedford.php" they are not redirected?
You can use (?!...)
negative assertions for that.
RewriteRule ^sample-(?!az|tx)([a-z][a-z]).php /state.php?m=$1
Write them immediately before the character matching group. It would work the same for the cities.
精彩评论