I've configured IIS 7 to require SSL. I'm wondering if I can automatically redirect non-ssl requests to be encrypted.

For example, if a user types in http://domain.com, can IIS redirect the request to https://domain.com rather than display the 403 error page?


There are a few ways you can do this but if you have the URL Rewrite Module installed, it's fairly easy and a good way to do it.

You can paste the below configuration into your site's web.config file (enclosed in the <system.webServer></system.webServer> section)

   <rule name="https redirect">      
      <match url="(.*)" ignoreCase="false" />     
            <add input="{HTTPS}" pattern="off" ignoreCase="false" />      
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />    

OR you can use the IIS's UI to make a new rule like in the below screenshot.

Screenshot of IIS rewrite rule for redirecting http traffic to https.

| improve this answer | |
  • What does the off signify? this answer works btw – Dez Udezue Apr 6 '17 at 13:05

You could also use UrlRewriter.NET. The rules to use with that, look like this:

    <if header="HTTPS" match="^OFF$">
        <redirect url="(.*)" to="https://yourdomain.com$1"/>
| improve this answer | |

First, you need to disable 'Require SSL' in SSL Settings. Then you can follow skottt's solution.

BTW, I followed RuslanY Blog's blog http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.