forum

Home / DeveloperSection / Forums / web.config redirect non-www to www

web.config redirect non-www to www

John Smith 1421 15-Jun-2018

I want to redirect non-www urls to www url for both http and https . I tried following rules in web.config but not working. 

please help

 <rewrite>
    <rules>
      <!-- For force ssl -->
      <rule name="Redirect to WWW" stopProcessing="true">
        <match url=".*" />
        <conditions>
          <add input="{HTTP_HOST}" pattern="^domain.com$" />
        </conditions>
        <action type="Redirect" url="http://www.domain.com/{R:0}" redirectType="Permanent" />
      </rule>
      <!-- For force ssl -->
      <!-- For force www -->
      <rule name="Redirect to WWW https" stopProcessing="true">
        <match url=".*" />
        <conditions>
          <add input="{HTTPS}" pattern="^domain.com$" />
        </conditions>
        <action type="Redirect" url="https://www.domain.com/{R:0}" redirectType="Permanent" />
      </rule>
      <!-- For force www -->
    </rules>
  </rewrite>
  <!-- For force ssl and www -->


Updated on 15-Jun-2018
I am best.

Can you answer this question?


Answer

1 Answers

Liked By