Reputation: 101
I'm writing a url rewrite regex to find strings having dash between each slash pair, for example,
/aaa-bb/cc/dd-ee-ff/gg
should match aaa-bb
and dd-ee-ff
. I need it to match nothing if url contains /test/
, so for url /aaa-bb/cc/test/dd-ee-ff/gg
, it should match nothing. I have written a regex
/\w+-(\w+(?!\.)-?)+
it will find all strings contains -
, but I can't add the pattern for the /test/
part.
Upvotes: 1
Views: 276
Reputation: 75
Immediately preceding your RewriteRule that contains your regex, add a rewrite condition to exclude urls that contain the substring /test/
anywhere in it. That RewriteCond would look like:
RewriteCond %{REQUEST_URI} !/test/
RewriteRule /\w+-(\w+(?!\.)-?)+ /some_place_else.html?parameters=$1
Upvotes: 1
Reputation: 21820
As far as I know, regex cannot maintain a state, and for that reason you should separate what you're doing into two separate checks, nesting the dash check within the test check.
if(!hasTest) {
//check for dashes
}
Upvotes: 1