o redirect HTTP to HTTPS in IIS (Internet Information Services), you have a few options depending on your setup. Here’s how to do it step-by-step:
Method 1: Using IIS HTTP Redirect Module
This works best for simple websites and requires the HTTP Redirect feature to be installed.
Steps:
-
Open IIS Manager.
-
Select your website from the Connections pane.
-
Double-click on HTTP Redirect in the Features View.
-
Check “Only redirect requests to content in this directory (not subdirectories)”.
-
Enter your HTTPS URL, e.g.,
https://www.example.com. -
Check “Only respond to requests to this site”.
-
Click Apply on the right pane.
-
In the Actions pane, click Apply to save the changes.
Method 2: Using Web.config File
This is preferred if you want to maintain the redirects in a deployable file.
Add this to your web.config inside <system.webServer>:
<configuration>
<system.webServer>
<rewrite>
<rules>
<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}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Make sure the URL Rewrite module is installed in IIS for this to work.
Method 3: Use IIS GUI (URL Rewrite Module)
-
Open IIS Manager.
-
Select your site.
-
Double-click URL Rewrite.
-
Click “Add Rules…” in the right Actions panel.
-
Select “Blank Rule” under Inbound Rules, then click OK.
-
Name it something like
Redirect to HTTPS. -
Under Conditions, click Add:
-
Condition input:
{HTTPS} -
Check if input string:
Matches the Pattern -
Pattern:
off
-
-
Under Action:
-
Action type:
Redirect -
Redirect URL:
https://{HTTP_HOST}/{R:1} -
Redirect type:
Permanent (301)
-
-
Click Apply to save.
Here’s a ready-to-use web.config file that redirects all HTTP requests to HTTPS using the URL Rewrite module in IIS.
This works only if the URL Rewrite module is installed on your server.
Sample web.config File:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<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}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Instructions:
-
Open or create a
web.configfile in your site’s root folder. -
Paste the above XML code.
-
Save the file.
-
Make sure the URL Rewrite module is installed on your IIS server.
How to Check if URL Rewrite Module is Installed:
-
Open IIS Manager.
-
Select your website.
-
In the Features View, look for URL Rewrite.
-
If you don’t see it, download and install it from Microsoft’s official site.
-
