开发者

How to Omit Matches from htaccess Regular Expression

开发者 https://www.devze.com 2023-02-15 04:07 出处:网络
RewriteEngine On RewriteBase / RewriteRule ^sample-([a-z][a-z]).php /state.php?m=$1 RewriteRule ^sample-([a-z^-]+).php /city.php?m=$1
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:

  1. 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?

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号