Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

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.

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

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

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

share|improve this answer
add comment

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

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

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/

share|improve this answer
    
Thanks, this worked for me! –  riaandelange Jul 29 '13 at 19:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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