libjup
libjup

Reputation: 4089

web.config redirect all requests to https://www

We want to redirect all incoming requests to https://www.domain.com

We have tried dozens of code snippes from the web but none covered all the examples from above.

Can anyone help with an appropriate web.config file for IIS?

Upvotes: 2

Views: 2451

Answers (2)

user123457
user123457

Reputation: 111

I got the same problem. This rule works for me.

    <rewrite>
        <rules>
            <clear />
            <rule name="Redirect non-www OR non-https to https://www">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^domain.com$" />
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://www.domain.com/{R:0}" redirectType="Permanent"/>
            </rule>
        </rules>
    </rewrite>

Upvotes: 3

Superzadeh
Superzadeh

Reputation: 1106

The best way to this is via your DNS records + some IIS configuration.

  • Add a CName that redirects domain.com to www.domain.com
  • In IIS, create a "fake" website and edit its binding to handle http://www.domain.com
  • Configure an HTTP redirection in the web.config of this "fake" website (or through the UI) to redirect requests coming from the host name www.domain.com to https://www.domain.com$S$Q ($S and $Q allows you to keep the parameters after the redirect, see this link for more info)
  • Finally, remove the HTTP binding your website (only use https binding on this one).

Upvotes: 1

Related Questions