1

I am using IIS URL Rewrite and this one has stumped me.

I am redirecting a URL with specific subfolder to a new URL.

e.g. https://myapp.example.com/customsite1 redirected to https://newsite1-myapp.example.com

If I use this pattern:

^(.*)customsite1(.*)$

It works fine. The problem is there might be arguments added to the URL that also use the word customsite1. So I thought "of course, the easy way to fix to this is match on /customsite1"

But it never works.

^(.*)/customsite1(.*)$ 

will never match https://myapp.example.com/customsite1 even though the Test pattern feature says it will.

What am I missing here?

  • Please include the actual config directives you are using. What are the (.*) subgroups in your regex for? – MrWhite Dec 13 '18 at 1:33
1

I guess you're referring to the Match URL pattern field, this one:

The first fields of the new rule editor

In that case the values received always start without the first / and don't include the Query String parameters either (if you need to make decisions based on the query string, it must be processed with a condition rule (using the {QUERY_STRING} field in the condition input).

So, if the arguments are added to the Query String it shouldn't worry you at all. If the arguments you're mentioning are part of the URL, for example:

https://myapp.example.com/customsite1/action/param1/customsite1/param3

then you should use a regular expression similar to this one:

^customsite1(/.*){0,1}$

This matches "/customsite1" with or without the final slash and anything that goes after it, and captures that part. It doesn't matter if any parts of the URL add the same name as the main folder you're trying to redirect.

In the "Redirect URL" field of the redirect action you can write:

https://newsite1-myapp.example.com{R:1}

The action URL

without the last slash since it is captured with the regular expression, and it will redirect request to that folder to the new domain, adding the rest of the URL after your folder.

HTH

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.