Redirect Website to https (Force HTTPS) (IIS) Print

  • 200

If your website has an active SSL Certificate, it will work under the secure address of https:// (for example, https://alpha.net.bd). You may want to redirect all incoming requests to your website to always go to https (secure) rather than http (unsecure). This is also known as "Force SSL" or "Force HTTPS".

Some CMS's such as Wordpress already have an option to Force SSL in the backend section so the below only applies for other websites.

In order to redirect (force) the website to https, a rewrite rule needs to be added into the web.config file in the root of the website.

Look for a file called "web.config" which should be located in the root of your website. 

If you do not see a web.config file, you can create one by clicking "Create File" button.

Once you have opened up the web.config file, you can place a Rewrite Rule to redirect all requests to https instead of http. It is important that tags that make up the rule are placed in the correct location of your web.config file. If not, it may break your website. 

If you are confident in placing rewrite rules, the following is an example of text to make up a full web.config file that will redirect all requests to https. If you have a blank or new web.config, copy and paste the following into the web.config file.

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

 

If you have an existing web.config file, then you may already have existing tags for <rewrite> and <rules>. If you do, locate the starting <rules> tag and paste the below

<rule name="Redirect to https" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

 


Was this answer helpful?

« Back