Author: Guitarman 04/10/2021
Language:
HTML, XML
Tags:
Add this to your web.config file to redirect users to HTTPS on IIS web servers. (ASP.Net and PHP)
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.
<?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>