IIS 7 and Above
URL Rewrite Module
URL Redirect with exact match problem
Last post Oct 03, 2018 01:54 PM by srgould41
Oct 02, 2018 01:35 PM|srgould41|LINK
I have been struggling with a specific pattern matching solution. We have a large site with lots of subdomains. The subdomain URL's have always been easy to match. We we so many site that we have to be careful with redirects so we don't redirect the wrong
requests. To make matters worse we have somewhere around 50 rules and I suspect the number of rules is causing issues, but that is for another time.
Here is the info on my issue. We get requests for company.com as well as
www.company.com and need to handle both.
Here is the path I am trying to redirect.
I need to be able to grab back references also. I have not been able to match the "af" part without matching more than intended. For example my rule also matches "after", "afghanistan", etc.
Right now I have this in place.
For conditions I am using http_host and ^(?:www\.)?(company+\.com)$
Under match URL I have af(.*)
This grabs too much and also not enough. For some reason any requests with
www.company.com don't get evaluated.
Anyway, I need to evaluate just www.company.com/af and company.com/af as well as the back reference so I can pass that along to the new url.
I have also tried ^(?:www\.)?(company+\.com)/af$ and the URL match of (.*)
Can anyone help?
Oct 02, 2018 05:16 PM|Rovastar|LINK
^af$ is all you need in your pattern match.
There are many ways to do URLrewriting and every solution we get will be different but I always use the standard pattern for URL stem and have a separate condition for the HTTP_HOST matching rather then doing everything in one go which I find complicates
matter far too much.
Oct 02, 2018 06:28 PM|srgould41|LINK
Except that doesn't catch af/ or af/something.
Oct 02, 2018 07:31 PM|srgould41|LINK
Actually you were on to something. I used this: ^af(/?.*) to catch the back references. The problem is that is still catches too much and redirects other content such as after. It appends the "ter" on the redirect URL with fails. If I have no other choice
I will not allow R back references, but it would be nice.
This works too, ^af(/?$), but kills the back references and any URL that has more text. For example af/about fails.
What I didn't mention is that our site has all the main content running in Ingeniux. We have a separate site on the same server for URL redirects that work for all other domains and sub domains such as site1.company.com. For company.com I had to move the
redirect into the ingeniux site and how it works great, except for the above issue.
Oct 02, 2018 09:59 PM|lextm|LINK
Oct 03, 2018 01:54 PM|srgould41|LINK
^(ar|ar/.*)$ was a closer, but not correct. However, you gave me an idea that ended up working.
This covered all scenarios. The R:2 query string holds the back reference I needed.
Thanks for all your help people!