user1275954
user1275954

Reputation: 36

Regex to match all except URLs that contain specific directory?

I need a regular expression for IIS URL Rewrite that will process the rule only when the expression matches any bit of the URL EXCEPT a specific sub-root directory.

Example:

www.mysite.com/wordpress - process rule on any URL that starts with /wordpress after the domain name

www.mysite.com/inventory - do not process rule on any URL that starts with /inventory after the domain name

Tried .*(?<!^\/inventory\/.*) but it still matches the entire string.

Upvotes: 0

Views: 961

Answers (1)

Jeff Y
Jeff Y

Reputation: 2456

You need a lookahead rather than lookbehind. Something like this I think:

^([^/]*/){1}(?!inventory\b)

Where you change 1 to 2 when the exclusion is needed at the next lower sublevel, etc.

Upvotes: 1

Related Questions