{"id":2522,"date":"2013-10-16T20:54:03","date_gmt":"2013-10-16T12:54:03","guid":{"rendered":"http:\/\/rmohan.com\/?p=2522"},"modified":"2013-10-16T21:01:30","modified_gmt":"2013-10-16T13:01:30","slug":"iis7-redirect-http-to-https","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2522","title":{"rendered":"IIS7 redirect HTTP to HTTPS"},"content":{"rendered":"<header>\n<h1><a href=\"http:\/\/blog.shiraj.com\/\">Memorise<\/a><\/h1>\n<\/header>\n<h2>IIS7 redirect HTTP to HTTPS<\/h2>\n<p><time>April 14, 2013<\/time><\/p>\n<p>The method of setting up an IIS7 redirect HTTP to HTTPS is to Require SSL on the site or part of the site and set up a custom 403.4 error page. To do this, just following these steps:<\/p>\n<ol>\n<li><a href=\"http:\/\/www.sslshopper.com\/article-installing-an-ssl-certificate-in-windows-server-2008-iis-7.0.html\">Install your SSL certificate in IIS 7<\/a>\u00a0and bind it to your website<\/li>\n<li>In IIS, click on the site name, and go to the\u00a0<strong>SSL Settings\u00a0<\/strong>section<\/li>\n<li>Check\u00a0<strong>Require SSL<\/strong>\u00a0and\u00a0<strong>Require 128-bit SSL<\/strong>\u00a0and click\u00a0<strong>Apply<\/strong><\/li>\n<li>After doing this, users will normally receive error:<\/li>\n<li>Create a new text file and paste the following into it:<\/li>\n<\/ol>\n<p>&lt;html&gt;<br \/>\n&lt;head&gt;&lt;title&gt;Redirecting\u2026&lt;\/title&gt;&lt;\/head&gt;<br \/>\n&lt;script language=\u201dJavaScript\u201d&gt;<br \/>\nfunction redirectHttpToHttps()<br \/>\n{<br \/>\nvar httpURL= window.location.hostname + window.location.pathname + window.location.search;<br \/>\nvar httpsURL= \u201chttps:\/\/\u201d + httpURL;<br \/>\nwindow.location = httpsURL;<br \/>\n}<br \/>\nredirectHttpToHttps();<br \/>\n&lt;\/script&gt;<br \/>\n&lt;body&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>6. Save the file as\u00a0<strong>redirectToHttps.htm<\/strong>\u00a0in your C:\\Inetpub directory<\/p>\n<p>7. Back in IIS, click on the site name and double-click the\u00a0<strong>Error Pages<\/strong>\u00a0option<\/p>\n<p>8. Click\u00a0<strong>Add\u2026<\/strong>\u00a0and enter\u00a0<strong>403.4<\/strong>\u00a0as the Status code. Browse for the redirectToHttps.htm file you just created and click\u00a0<strong>OK<\/strong><\/p>\n<p>9. Select the error code and press\u00a0<strong>Edit Feature Settings\u2026<\/strong><\/p>\n<p>10. Click the\u00a0<strong>Custom error pages<\/strong>\u00a0option and again browse for the redirectToHttps.htm file<\/p>\n<p>11. Test the site by going to http:\/\/www.yoursite.com and making sure it redirects<\/p>\n<p>A caveat of using a custom error page to do an IIS7 redirect from HTTP to HTTPS is that the web browser must have JavaScript enabled for the redirection to work.<\/p>\n<p>If you get \u201cLock violation\u201d error in IIS 7.5<\/p>\n<p>All you need to do is to open file \u201c%windir%\\System32\\inetsrv\\config\\applicationHost.config\u201d and remove \u2018defaultPath\u2019 from the following line:<\/p>\n<p>&lt;httpErrors lockAttributes=\u201dallowAbsolutePathsWhenDelegated,defaultPath\u201d&gt;<\/p>\n<p>&nbsp;<\/p>\n<h2>GUI Version<\/h2>\n<p>&nbsp;<\/p>\n<p>URL Rewrite has a GUI to allow you to enter rules within IIS 7; in the background all this does is edit the web.config file of the site. I will show you how to create a rule both ways.<\/p>\n<p>In the following example we will redirect HTTP to HTTPs using URL Rewrite. You will need the following items completed in order for this to work correctly.<\/p>\n<p>&#8211; SSL Certificate for site installed in IIS.<br \/>\n&#8211; Site properly installed and configured for SSL (site set up and binding in IIS configured).<br \/>\n&#8211; URL Rewrite 2.0 is installed on the sever.<\/p>\n<h2>GUI Version<\/h2>\n<p>&#8211; Select the website you wish to configure<br \/>\n&#8211; In the \u201cFeatures View\u201d panel, double click URL Rewrite<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2523\" alt=\"031010_2252_Automatical1\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical1.png\" width=\"501\" height=\"467\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical1.png 501w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical1-300x279.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical1-150x139.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical1-400x372.png 400w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/a><\/p>\n<p>You will notice there are currently no rules configured for this site. Click \u201cAdd Rules\u2026\u201d in the Actions menu to the right of the \u201cFeatures View\u201d panel<a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2524\" alt=\"031010_2252_Automatical2\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical2.png\" width=\"515\" height=\"211\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical2.png 515w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical2-300x122.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical2-150x61.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical2-400x163.png 400w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Use the default \u201cBlank rule\u201d and press \u201cOK\u201d.<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2525\" alt=\"031010_2252_Automatical3\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical3.png\" width=\"353\" height=\"237\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical3.png 353w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical3-300x201.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical3-150x100.png 150w\" sizes=\"(max-width: 353px) 100vw, 353px\" \/><\/a><\/p>\n<p>When editing a rule there are the \u201cName\u201d field and 4 configuration pull down boxes.<\/p>\n<p>&nbsp;<\/p>\n<p>&#8211; Enter \u201cRedirect to HTTPS\u201d in the name field.<br \/>\n&#8211; Next we will configure the first configuration pull down box called \u201cMatch URL\u201d, on the right side of \u201cMatch URL\u201d press the down arrow to expand the box.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Within the \u201cMatch URL\u201d configuration box we will set the following settings:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Requested URL:<\/strong> Matches the Pattern<br \/>\n<strong>Using:<\/strong> Regular Expressions<br \/>\n<strong>Pattern:<\/strong> (.*)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2526\" alt=\"031010_2252_Automatical4\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical4.png\" width=\"452\" height=\"223\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical4.png 452w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical4-300x148.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical4-150x74.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical4-400x197.png 400w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical3.png\">We can now edit the next configuration pull down box which is \u201cConditions\u201d, Press \u201cAdd\u2026\u201d to add a new condition to the configuration<\/a><\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2527\" alt=\"031010_2252_Automatical5\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical5.png\" width=\"469\" height=\"231\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical5.png 469w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical5-300x147.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical5-150x73.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical5-400x197.png 400w\" sizes=\"(max-width: 469px) 100vw, 469px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We will configure the condition with the following settings:<\/p>\n<p><strong>Condition Input<\/strong>: {HTTPS}<br \/>\n<strong>Check if input string<\/strong>: Matches the Pattern<br \/>\n<strong>Pattern<\/strong>: ^OFF$<\/p>\n<p>Press \u201cOK\u201d<\/p>\n<p>href=&#8221;http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical7.png&#8221;&gt;<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2533\" alt=\"031010_2252_Automatical7\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical7.png\" width=\"268\" height=\"178\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical7.png 268w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical7-150x99.png 150w\" sizes=\"(max-width: 268px) 100vw, 268px\" \/> <a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2532\" alt=\"031010_2252_Automatical8\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical8.png\" width=\"448\" height=\"217\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical8.png 448w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical8-300x145.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical8-150x72.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical8-400x193.png 400w\" sizes=\"(max-width: 448px) 100vw, 448px\" \/><\/a> <a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2531\" alt=\"031010_2252_Automatical9\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical9.png\" width=\"448\" height=\"370\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical9.png 448w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical9-300x247.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical9-150x123.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical9-400x330.png 400w\" sizes=\"(max-width: 448px) 100vw, 448px\" \/><\/a> <a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2530\" alt=\"031010_2252_Automatical10\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical10.png\" width=\"261\" height=\"99\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical10.png 261w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical10-150x56.png 150w\" sizes=\"(max-width: 261px) 100vw, 261px\" \/><\/a><\/p>\n<p>You should now see the rule configured on the main screen of the URL Rewrite module.<\/p>\n<p>Test your site, it should now redirect from HTTP to HTTPS.<\/p>\n<p>If we exam the web.config file we can see where the rule was entered. If we entered the rule directly into the web.config file it would show up in the GUI.<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical11.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2529\" alt=\"031010_2252_Automatical11\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical11.png\" width=\"515\" height=\"325\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical11.png 515w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical11-300x189.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical11-150x94.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical11-400x252.png 400w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/a><br \/>\nTest your site, it should now redirect from HTTP to HTTPS.<\/p>\n<p>If we exam the web.config file we can see where the rule was entered. If we entered the rule directly into the web.config file it would show up in the GUI.<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2528\" alt=\"031010_2252_Automatical12\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical12.png\" width=\"628\" height=\"312\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical12.png 628w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical12-300x149.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical12-150x74.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2013\/10\/031010_2252_Automatical12-400x198.png 400w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/a><\/p>\n<p>Web.Config Rule<\/p>\n<p>You can also edit the web.config file of the site directly and you will be able to see the rule in the GUI. You will need to enter the following within the &lt;system.webServer&gt; &lt;\/system.webServer&gt; elements.<\/p>\n<p>&nbsp;<\/p>\n<div>\n<div><code>&lt;<\/code><code>rule<\/code> <code>name<\/code><code>=<\/code><code>\"Redirect to HTTPS\"<\/code> <code>stopProcessing<\/code><code>=<\/code><code>\"true\"<\/code><code>&gt;<\/code><\/div>\n<div><code>&lt;<\/code><code>match<\/code> <code>url<\/code><code>=<\/code><code>\"(.*)\"<\/code> <code>\/&gt;<\/code><\/div>\n<div><code>&lt;<\/code><code>conditions<\/code><code>&gt;&lt;<\/code><code>add<\/code> <code>input<\/code><code>=<\/code><code>\"{HTTPS}\"<\/code> <code>pattern<\/code><code>=<\/code><code>\"^OFF$\"<\/code> <code>\/&gt;<\/code><\/div>\n<div><code>&lt;\/<\/code><code>conditions<\/code><code>&gt;<\/code><\/div>\n<div><code>&lt;<\/code><code>action<\/code> <code>type<\/code><code>=<\/code><code>\"Redirect\"<\/code> <code>url<\/code><code>=<\/code><code>\"<a href=\"https:\/\/\">https:\/\/<\/a>{HTTP_HOST}\/{R:1}\"<\/code> <code>redirectType<\/code><code>=<\/code><code>\"SeeOther\"<\/code> <code>\/&gt;<\/code><\/div>\n<div><code>&lt;\/<\/code><code>rule<\/code><code>&gt;<\/code><\/div>\n<div>When implementing this solution you need to make sure to use relative paths for all references on your page because there is a possibility you will get a warning asking you if you want to display secure and insecure items. For example, if you have a logo on your page and the URL to this logo is http:\/\/domain\/images\/logo.jpg, do not use the whole path because including the http:\/\/ will hard code this image to use http and not https<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p> Memorise IIS7 redirect HTTP to HTTPS <\/p>\n<p>April 14, 2013<\/p>\n<p>The method of setting up an IIS7 redirect HTTP to HTTPS is to Require SSL on the site or part of the site and set up a custom 403.4 error page. To do this, just following these steps:<\/p>\n<p> Install your SSL certificate in IIS 7 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2522"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2522"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2522\/revisions"}],"predecessor-version":[{"id":2535,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2522\/revisions\/2535"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}