Web Development
Merge Redirect From Non-Www To Www And Secure Connection In One URL Rewriting Rules To Avoid Many Redirects

Merge Redirect From Non-Www To Www And Secure Connection In One URL Rewriting Rules To Avoid Many Redirects

For Web optimization we want to keep one URL to each page, to stay away from a few URLs that go to a similar page and coming about into partitioned reports.

so we utilize the URL rework rules to divert non-www to www by adding the beneath rule to the web.config document

<rule name="NonWwwToWww" stopprocessing="true">
   <match url="(.*)"></match>
   <conditions>
      <add input="{HTTP_HOST}" pattern="^mydomain.com$"></add>
   </conditions>
   <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirecttype="Permanent"></action>
</rule>

also, utilize the beneath to divert from http to https

    
<rule name="RedirectToHTTPS" stopprocessing="true"> <match url="(.*)"></match>
  <conditions>
    <add input="{HTTPS}" pattern="off" ignorecase="true"></add>
  </conditions>
  <action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirecttype="Permanent">
  </action>
</rule>

however, this will result to 2 redirections assuming clients demand URL : "http://mydomain.com" design. so to keep away from that we can blend the both in one rule by the underneath:

<rule name="WWW and SSL" enabled="true" stopprocessing="true">
  <match url="(.*)"></match>
  <conditions logicalgrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^[^www]"></add>
    <add input="{HTTPS}" pattern="off"></add>
  </conditions>
 <action type="Redirect" url="https://www.mydomain.com/{R:1}" appendquerystring="true" redirecttype="Permanent">
 </action>
</rule>
String to Date and Time object conversion – Android
String to Date and Time object conversion – Android
How to SetBasePath in ConfigurationBuilder in Core 2.0 ?
How to SetBasePath in ConfigurationBuilder in Core 2.0 ?

Related Posts