Categories
web.config: Redirect http to https
To set up a redirect to https you first need to be logged into the contol panel, then go to the file manager.

Then click on your website and then on the wwwroot folder.

Find a file called web.config and click on the draft block.

You can now make a redirect from https:// to https:// with the code below. The blue part should already be in your web.config, as this is the default config. To make it easy we have placed the default web.config below.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.html" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="Default.aspx" />
<add value="index.html" />
<add value="index.php" />
<add value="index.asp" />
</files&>
</defaultDocument>
</system.webServer>
</configuration>
The red part you have to add yourself for the redirect, this is the code for the redirect. You can place this under<system.webServer> below is the code for the redirect.
<rewrite>
<rules>
<rule name="Redirect non-www OR non-https to https://www"> <match url=".
*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^myhostingpartner.com$" /> <add input=
"{HTTPS}" pattern="off" />
</conditions> <action type="Redirect" url=
"https://www.myhostingpartner.co.uk/{R:0}" redirectType="Permanent" />
</rule>
*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^myhostingpartner.com$" /> <add input=
"{HTTPS}" pattern="off" />
</conditions> <action type="Redirect" url=
"https://www.myhostingpartner.co.uk/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
However, you still need to adapt the links to your domain and the corresponding extension. To make this a bit easier we have put the links in the green marked, you need to adapt them to your own domain and extension. Below is an example.
<add input="{HTTP_HOST}" pattern="^myhostingpartner.com$" />
With thepiece of code below you have to Please note that you have to make the right choice between https:// and https://www. This depends on how you have set it up on your own website.
Below is the full web.config that you can use to further set up the redirect to https://.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rules>
<rule name="Redirect non-www OR non-https to https://www"> <match url=".
*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^myhostingpartner.com$" /> <add input=
"{HTTPS}" pattern="off" />
</conditions> <action type="Redirect" url=
"https://www.myhostingpartner.co.uk/{R:0}" redirectType="Permanent" />
</rule>
*" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^myhostingpartner.com$" /> <add input=
"{HTTPS}" pattern="off" />
</conditions> <action type="Redirect" url=
"https://www.myhostingpartner.co.uk/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite><directoryBrowse enabled="false" />
</system.webServer>
</configuration>