HS Banner
Back
Redirect HTTP to HTTPS on IIS

Author: Guitarman 04/10/2021
Language: HTML, XML
Views: 284
Tags:


Description:

Add this to your web.config file to redirect users to HTTPS on IIS web servers. (ASP.Net and PHP)

Article:

Adding rewrite rules to your web.config you can redirect users to HTTPS on IIS web servers. This will work with ASP.NET and PHP sites hosted on IIS.

<rewrite>
      <rules>
        <rule name="httpTohttps" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
</rewrite>

Note:
If you are hosting your PHP site on an IIS server just create a web.config file in the root directory of your site and past the full source code below into that file.

Full Source Code:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="httpTohttps" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>


Back
Comments
Add Comment
There are no comments yet.