I am currently rewriting a URL, however my RegEx expression is catching a directory I want to be ignored.
The rewrite rule is
^people/([A-Za-z0-9\-\_]+)/?$
...Which catches everything that matches. However, I would like to exclude a directory, People_Search, so for instance...
/people/John_Smith
...will forward, but
/people/People_Search
...should not suppose to be.
That's the only term I want to look for, so if it exists anywhere in the string, I want to ignore it.
Any ideas?
Regex has a thing called a "non capturing negative lookahead assertion" which basically says "don't match the following". It looks like this:
^people/(?!People_Search)([A-Za-z0-9\-\_]+)/?$
Whether you can use this depends on the rewrite engine you use, and the level of regex support that's included in it. I'd expect that most common rewriters support this.
FYI: There are also negative lookbehind assertions(?<!), and also postive versions of the lookahead (?=) and lookbehind (?<=) assertions.
Tutorial: http://www.regular-expressions.info/lookaround.html
^people/(?!People_Search)([A-Za-z0-9\-\_]+)/?$
A negative lookahead to prevent matching People_Search
after people/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With