We have a hosted Umbraco site that is using the UrlRewriting.net config file to handle redirects. The client has about 60 landing domains that they have bought and pointed at the site, however they want to 301 redirect all the landing domains to the actual domain along with anything after the domain, for this example I'll call it
I'm using the below regex, which redirects anything that isn't the main site back to the mainsite with the pages appended.
http://www.anything.co.uk/a-page is correctly getting redirected to
http://www.anything.com/subpage/another-page is getting redirected to
http://www.mainsite.com/another-page and missing the
The error is outside of the negative lookahead, but I can't work out how to fix it.
Any help is much appreciated.
Your regex is matching too greedily. If you change the RegEx to this:
It will match only until it hits the first forward slash after the domain. So $2 should contain subpage/another-page in your example.
I can highly recommend a tool called Expresso for writing and testing Regular Expressions. It allows you to break down what a RegEx is doing, and run tests against them.