Iis url redirect http to non www https

I need to redirect from

www.domain.de at https://domain.de -Works

http://www.domain.de at https://domain.de -Works

http://domain.de at https://domain.de - not working

rewrite> <rules> <rule name="Imported Rule 1" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^www\.(.+)$" /> </conditions> <action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite> 
+7
source share
4 answers

I think this will work for you, the search template has an optional WWW and redirects using a C: 2 backlink, the rule has a condition for executing only with https.

This is the template:

 "^(www\.)?(.*)$" 

Where:

 {C:0} - www.domain.de {C:1} - www. {C:2} - domain.de 

Here is the rule in full:

  <rewrite> <rules> <rule name="SecureRedirect" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTPS}" pattern="off" /> <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" /> </conditions> <action type="Redirect" url="https://{C:2}" redirectType="Permanent" /> </rule> </rules> </rewrite> 
+20
source

If you need something more flexible than your three examples, change your HTTP_HOST pattern to: \w+\.\w+$ . This will work for all three examples plus anything else, like subdomain.abcdef.domain.de.

If you use this regular expression, either enclose it in parentheses, or change C: 1 to C: 0 in your action.

+2
source

If you want to redirect www to www:

  • Add a DNS record for www.yourdomain.com to refer to your serverโ€™s public IP address.
  • Then you need to edit the bindings of your site and "Add a binding" www.yourdomain.com
  • Add a rewrite rule to your site using iis:
 <rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions> <add input="{CACHE_URL}" pattern="*://www.*" /> </conditions> <action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" /> </rule> 

Link: http://madskristensen.net/post/url-rewrite-and-the-www-subdomain

0
source

These rewrite rules correspond to the following URLs:

All of them will be redirected to: https://example.com

These rewrite rules may be redirected twice due to individual rules. (I'm new to regex)

 <configuration> <system.webServer> <rewrite> <rules> <rule name="HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions> <add input="{HTTPS}" pattern="off" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" /> </rule> <rule name="WWW" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" /> </conditions> <action type="Redirect" url="https://example.com{PATH_INFO}" /> </rule> </rules> </rewrite> </system.webServer> </configuration> 
-one
source

All Articles