0

Hi please help me in fixing redirect issue of my website.

I want redirect my domain.com, www.domain.com to https:// www. domain.com.

presently i have the following code to redirect.

<rule name="CanonicalHostNameRule1" stopProcessing="true">
<match url="^(\w*/)?index\.php" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain\.com$" />
</conditions>
<action type="Redirect" url="https://www. domain.com/{R:1}" />
</rule>

<rule name="CanonicalHostNameRule2" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" />
</conditions>
<action type="Redirect" url="https://www. domain.com/{R:1}" />
</rule>

now, my domain.com is redirecting to https:// www. domain.com but, www . domain.com is not redirect to https version. I have tried few codes from search but i have getting redirect loop errors.Please share your suggestion to fix this issue.

gopi c
  • 1
  • 1

1 Answers1

0

This rule below will take care of http to https for both www and non www request and the final url will be same for all the request https://www.domain.com

Copy of the web config:

<rewrite>
     <rewriteMaps>
            <rewriteMap name="root">
                <add key="/root/" value="/" />
            </rewriteMap>
        </rewriteMaps>
        <rules>
            <rule name="To HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="SeeOther" />
            </rule>
        </rules>
    </rewrite>

You can do this by GUI and URL rewrite module:

enter image description here enter image description here

zman
  • 189
  • 2
  • 9