A common question that is often asked is how to auto-magically redirect HTTP requests for your web sites to HTTPS. Simply put, if someone types “http://www.yoursite.com” how can you redirect that request to “https://www.yoursite.com”?
This post is the simple answer to that question. IIS’s URL rewrite module can help us accomplish this as well as other rewrite tasks. For a complete look at how URL Rewriting works, take a look at the following MSDN article on URL Rewrite. Then look at the following as an example of what to add to your web.config:
<rewrite> <rules> <rule name="Redirect to HTTPS" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite>
wouldnt connect with my credentials – does not work – wasted a lot of time – is their some secret
Thanks for such a clear, concise example!
I utilized your configuration snippet in my web.config system.webserver section. This causes http://mywebsite/mywebapp to redirect to https://mywebsite which is not exactly my ideal redirection which ideally would be to https://mywebsite/mywebapp. How can I alter your snippet to achieve my desired result?