0

I tried almost all upvoted suggestions related to web.config changes for http to https redirection. Best way in asp.net to force https for an entire site?

But it's not working for me for my ASP.net site. I use GoDaddy shared hosting and have multiple sites in my account. I have ssl enabled only for one website and have to add it to filter so that other sites in the same account are not redirected to https. Here's my web.config:

<rewrite>
  <rules>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true" enabled="true">
      <match url="singledomain.*" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

I can access the site currently by both http and https. But it never redirects from http to https. Is the match condition correct, and if it is, what else could be the problem?

halfer
  • 19,824
  • 17
  • 99
  • 186
Ganesh S
  • 371
  • 6
  • 26
  • If I use then it works but other domains in my shared hosting also start serving over https and there is no ssl for those and so those domains do not load. – Ganesh S Dec 01 '19 at 13:28

2 Answers2

0

Found the solution here: https://stackoverflow.com/a/17066105/2535756 Posting the code here which worked:

<rewrite>
      <rules>
        <rule name="HTTP to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="(singledomain.com.*)" />
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent"  url="https://{HTTP_HOST}/{R:1}" />
        </rule>
      </rules>
    </rewrite>
Ganesh S
  • 371
  • 6
  • 26
0

With GoDaddy, in my experience, there is a setting in the Plesk app that actually will force a re-direct from HTTP to HTTPS.You can find this under your IIS settings under the Directory Security Settings and checking the Require SSL/TSL box. This forces the users' browser to use HTTPS instead of HTTP.

Hounddog75
  • 71
  • 6
  • I am old account where they have not migrated me to Plesk. I got to know all this after I got the SSL. They asked me to let this hosting account expire and migrate to new Plesk during renewal otherwise I will have to buy some bulk SSL for multiple domains in my account :( – Ganesh S Dec 02 '19 at 07:07
  • You need to use URL Rewrite on your code, please check https://stackoverflow.com/questions/9823010/how-to-force-https-using-a-web-config-file – Douglas Thomas Dec 05 '19 at 07:39