0

I'm trying to add a iis url rewrite rule in web.config. The rule should be as follows.

If the url does not contain www, then redirect to www However, if the Host contains, 'svha-prd-as-careservices-01' then do not redirect to www

Below is my code, the www redirect is working however, negate condition to check 'svha-prd-as-careservices-01' is not working. What am I missing?

<rule name="Redirect Non-WWW to WWW" enabled="true" stopProcessing="true">
                  <match url=".*" />
                  <conditions>
                    <add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)" />
                    <add input="{REQUEST_HOST}" pattern="^(.*)svha-prd-as-careservices-01(.*)" negate="true" />
                  </conditions>
                  <action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="true" />
0

1 Answer 1

0

Please check the second condition in your rule:

<add input="{REQUEST_HOST}" pattern="^(.*)svha-prd-as-careservices-01(.*)" negate="true" />

You probably mistakenly wrote {REQUEST_HOST} instead of {REQUEST_URI}.

Please modify it to the correct conditions and try again:

<add input="{REQUEST_URI}" pattern="^(.*)svha-prd-as-careservices-01(.*)" negate="true" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.