Question

I'm setting up URL Rewrite on an IIS and i need to match the following URLs using regex.

http://sub.mysite.com
sub.mysite.com
sub.mysite.com/
sub.mysite.com/Site1
sub.mysite.com/Site1/admin

but not:

sub.mysite.com/admin
sub.mysite.com/admin/somethingelse
sub.mysite.com/admin/admin

The site it self (sub.mysite.com) should not be "hardcoded" in the expression. Instead, it should be matched by something like .*.

I'm really blank on this one. I did find solutions to match the different URLs but once i try to combine them either none of them match or all of them do.

I hope someone can help me.

Was it helpful?

Solution

For your specific case, assuming you are matching the part after the domain (REQUEST_URI):

(?!/admin).*

(?!...) is a negative lookahead. I am not sure if it is supported in the IIS URL Rewrite engine. If not, a better approach would be to check for a complementary approach:

Or as @kirilloid said, just match /admin/? and discard (pay attention to slashes).

BTW. if you want to quickly test RegExps with a "visual" feedback, I highly recommend http://gskinner.com/RegExr/

OTHER TIPS

([A-Za-z0-9]+.)+.com(?!/admin)/?([A-Za-z0-9]+/?)*

this should do the trick

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top