1

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.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
FEi.TH
  • 91
  • 1
  • 6

2 Answers2

1

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
whoisgregg
  • 75
  • 10
1

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
}
Kristian
  • 21,204
  • 19
  • 101
  • 176