asp.net - How to redirect all non-www URLs to https://www. in IIS? -


i want add proper 301 permanent redirect rule in iis 8.5. i've added following rules not working.

 <rule name="redirect top domains non-www www" stopprocessing="true">           <match url="(.*)" />           <conditions logicalgrouping="matchall" trackallcaptures="false">             <add input="{http_host}" pattern=".*localhost.*" negate="true" />             <add input="{http_host}" pattern=".*stage\..*" negate="true" />             <add input="{http_host}" pattern=".*dev\..*" negate="true" />             <add input="{http_host}" pattern="^(http:\/\/){0,1}(www\.){0,1}([^\.]+)\.([^\.]+)$" ignorecase="true" />           </conditions>           <action type="redirect" url="https://www.{c:3}.{c:4}" redirecttype="permanent" />         </rule> 

conditions

to summarize, every url should in https , should have "www." prefix.

note: have installed url rewrite module in iis.

can please me achieve this?

i managed adding 2 url rewrite rules in web.config file:

  1. for redirecting non-www https://www.{domain}.com/...
  2. redirecting http https

    <rule name="redirect top domains non-www www" stopprocessing="true">       <match url="(.*)" />       <conditions logicalgrouping="matchall" trackallcaptures="false">         <add input="{http_host}" pattern=".*localhost.*" negate="true" />         <add input="{http_host}" pattern=".*stage\..*" negate="true" />         <add input="{http_host}" pattern=".*dev\..*" negate="true" />         <add input="{http_host}" pattern="^([^\.]+)\.([^\.]+)$" />       </conditions>       <action type="redirect" url="https://www.{http_host}/{r:1}" redirecttype="permanent" />       <servervariables>         <set name="redirect" value="false" />       </servervariables>  </rule>   <rule name="force https" enabled="true" stopprocessing="true">       <match url="(.*)" ignorecase="false" />       <conditions logicalgrouping="matchall" trackallcaptures="false">         <add input="{http_host}" pattern=".*localhost.*" negate="true" />         <add input="{http_host}" pattern=".*stage\..*" negate="true" />         <add input="{http_host}" pattern=".*dev\..*" negate="true" />         <add input="{https}" pattern="off" />       </conditions>       <action type="redirect" url="https://{http_host}/{r:1}" appendquerystring="true" redirecttype="permanent" />  </rule> 

all conditions negate="true" used exclusion. hence urls contains "localhost", "stage", , "dev" excluded url rewrite. can remove these conditions if not required.

read more negate attribute @ http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -