Adding an Inbound Rule to IIS [UrlRewite]

Currently, on my Production server, I have an incoming rule installed in which the file works for all my requirements.

The incoming rule is as follows.

Match URL section Requested URL: Matches the Pattern Using: Regular Expression Pattern: (.*) Ignore Case: checked. Conditions section Logical grouping: Match All. Input: {HTTPS} Type: Matches the Pattern Pattern: ^OFF$ Track capture groups across conditions: unchecked. Action section: Action type: Redirect Redirect URL: https://www.domainname.com/{R:0} Append query string: checked. Redirect Type: Permanent (301). 

My requirements: When the user enters

 https://beta.domain.com it should redirect to https://www.domain.com. 

if custom types

 http://beta.domain.com it should redirect to https://www.domain.com. 

If user type

 http://www.domain.com it should redirect to https://www.domain.com 

If user type

 http://domain.com it should redirect to https://www.domain.com 

Thanks in advance. Any help would be appreciated.

Thanks in advance.

+4
source share
1 answer

Does this not mean that there is a conditional? It checks if HTTPS is turned off, and only then a redirect will occur. If HTTPS is enabled, you should not redirect, otherwise you will end up with endless redirects.

If you always want the hostname to be www.domainname.com , you should add this as an additional condition. For instance:.

 <rule name="Force HTTPS and host name: www.domainname.com" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTPS}" negate="true" pattern="^ON$" /> <add input="{HTTP_HOST}" negate="true" pattern="^www\.domainname\.com$" /> </conditions> <action type="Redirect" url="https://www.domainname.com/{R:0}" appendQueryString="true" redirectType="Permanent" /> </rule> 

If either HTTPS not ON or HTTP_HOST not www.domainname.com , it will be redirected. Only if both values ​​are true will they not be redirected.

+3
source

Source: https://habr.com/ru/post/1414314/


All Articles