How to force HTTPS from web.config file?

The Microsoft URL Rewrite Module 2.0 for IIS 7 and above enables IIS administrators to create powerful customized rules to map request URLs to friendly URLs that are easier for users to remember and easier for search engines to find. You can use the URL Rewrite module to perform URL manipulation tasks. To use this rule below are the prerequisites.

1. IIS 7 or above with ASP.NET role service enabled.
2. URL Rewrite Module installed.

Click here for more information on the Rewrite Module.

When you want to force HTTP to HTTPS, you will need to add below code in your web.config file.

<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>

 


Was this answer helpful?

« Back

chat