{"id":111,"date":"2012-06-15T07:16:55","date_gmt":"2012-06-15T15:16:55","guid":{"rendered":"http:\/\/unmitigatedrisk.com\/?p=111"},"modified":"2012-06-16T16:36:52","modified_gmt":"2012-06-17T00:36:52","slug":"redirecting-http-to-https-in-iis","status":"publish","type":"post","link":"https:\/\/unmitigatedrisk.com\/?p=111","title":{"rendered":"Redirecting HTTP to HTTPS in IIS"},"content":{"rendered":"<p>So you have been using SSL on your IIS 7.5 or greater server\u00a0for some time now; to get here you had to do a few things:<\/p>\n<ol>\n<li>You\u00a0scrubbed\u00a0your site content to ensure all URLs are using their relative form, e.g. &#8220;src=&#8217;\/\/images\\image.png&#8221; or explicitly reference the use of HTTPS.<\/li>\n<li>You have tested for certificate and SSL related problems like mixed content,\u00a0appropriately\u00a0tagging cookies as secure.<\/li>\n<li>You have ensured that you\u00a0follow\u00a0the\u00a0<a href=\"https:\/\/www.ssllabs.com\/downloads\/SSL_TLS_Deployment_Best_Practices_1.0.pdf\">best practices guidance for SSL server configuration<\/a>\u00a0and verified you get an A on\u00a0\u00a0<a href=\"https:\/\/www.ssllabs.com\/ssltest\">SSLLabs<\/a>.<\/li>\n<\/ol>\n<p>Are you done? Not yet there are a few things left for you to do, the most obvious being redirecting all traffic to the SSL version of your site!<\/p>\n<p>This is easy enough to\u00a0accomplish\u00a0but before you do so you should probably monitor your CPU usage during your peak so to ensure you have some headroom. This\u00a0isn&#8217;t\u00a0likely to be a problem as <a href=\"http:\/\/www.imperialviolet.org\/2010\/06\/25\/overclocking-ssl.html\">most web-servers are not CPU<\/a> bound but it\u2019s always good to check.<\/p>\n<p>Once you know you are OK then it\u2019s just a matter of deciding which approach to use, you have two choices:<\/p>\n<ol>\n<li>Dynamically rewriting via code <a href=\"http:\/\/support.microsoft.com\/kb\/239875\">in your ASPX pages<\/a><\/li>\n<li>Using the IIS <a href=\"http:\/\/www.iis.net\/download\/URLRewrite\">URL Rewrite<\/a> \u00a0module<\/li>\n<\/ol>\n<p>If you are familiar with the IIS configuration you\u2019re probably asking yourself what about the \u201c<em>Require secure channel (SSL)<\/em>\u201d option in the IIS MMC? Unfortunately this doesn\u2019t do redirecting it only requires the use of SSL on a given site\/folder\/file.<\/p>\n<p>So how do you decide which approach to use? The answer to that question is dependent on both your environment and personal preference.<\/p>\n<p>For example if 100% of your site is ASPX based (no static HTML), you have your code structured so that there is a common include and you are not already using the <a href=\"http:\/\/www.iis.net\/download\/URLRewrite\">URL Rewrite<\/a> module I would use method one based on <a href=\"http:\/\/support.microsoft.com\/kb\/239875\">KB239875<\/a>.<\/p>\n<p>I suspect that these conditions will not be met for most people so let\u2019s focus on method two, using the <a href=\"http:\/\/www.iis.net\/download\/URLRewrite\">URL Rewrite<\/a> \u00a0module.<\/p>\n<p>This approach has a number of benefits, for one having this module allows you to leverage remapping for other purposes also for example maintaining old links that have SEO value. From a security standpoint it\u2019s also a good approach as it keeps this decision one of policy that is enforced in a central place.<\/p>\n<p>To use the URL rewrite approach you will need to do the following:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\">1. Install the URL Rewrite module (<a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?displaylang=en&amp;id=5747\">x86<\/a>, <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=7435\">x64<\/a>).<\/p>\n<p style=\"padding-left: 30px;\">2. Add a rule to rewrite all HTTP URLs to HTTPS.<\/p>\n<p style=\"padding-left: 30px;\">a. Open your \u201cweb.config\u201d with your favorite editor.<\/p>\n<p style=\"padding-left: 30px;\">b. Find the \u201cconfiguration\\system.webserver\\rewrite\\rules\u201d section.<\/p>\n<p style=\"padding-left: 30px;\">c. Add the following text block:<\/p>\n<blockquote style=\"padding-left: 30px;\">\n<p style=\"padding-left: 30px;\">&lt;rule name=&#8221;Redirect to HTTPS&#8221; stopProcessing=&#8221;true&#8221;&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;match url=&#8221;(.*)&#8221; \/&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;conditions&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;add input=&#8221;{HTTPS}&#8221; pattern=&#8221;^OFF$&#8221; \/&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;\/conditions&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;action type=&#8221;Redirect&#8221; url=&#8221;https:\/\/{HTTP_HOST}\/{R:1}&#8221; redirectType=&#8221;Permanent&#8221; \/&gt;<\/p>\n<p style=\"padding-left: 30px;\">&lt;\/rule&gt;<\/p>\n<\/blockquote>\n<p style=\"padding-left: 30px;\">3. Restart IIS.<\/p>\n<p style=\"padding-left: 30px;\">\n<p>Now just go to your website over HTTP and you will see you are redirected to the HTTPS instance of the site.<\/p>\n<p>&nbsp;<\/p>\n<p>Ryan<\/p>\n<h6>Additional Resources<\/h6>\n<p><a href=\"http:\/\/learn.iis.net\/page.aspx\/465\/url-rewrite-module-configuration-reference\/\">IIS Rewrite Module Configuration Reference<\/a><\/p>\n<p><a href=\"http:\/\/ruslany.net\/2009\/04\/10-url-rewriting-tips-and-tricks\/\">10 URL Rewriting Tips and Tricks<\/a><\/p>\n<p><a href=\"http:\/\/www.jppinto.com\/2010\/03\/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0\/\">Automatically redirect HTTP requests to HTTPS on IIS7 using URL Rewrite 2.0<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you have been using SSL on your IIS 7.5 or greater server\u00a0for some time now; to get here you had to do a few things: You\u00a0scrubbed\u00a0your site content to ensure all URLs are using their relative form, e.g. &#8220;src=&#8217;\/\/images\\image.png&#8221; or explicitly reference the use of HTTPS. You have tested for certificate and SSL related [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[21,33,17,168,6,19],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-security","tag-best-practices","tag-iis","tag-microsoft","tag-security","tag-ssl","tag-x509"],"_links":{"self":[{"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=111"}],"version-history":[{"count":0,"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=\/wp\/v2\/posts\/111\/revisions"}],"wp:attachment":[{"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unmitigatedrisk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}