{"id":442,"date":"2018-11-01T22:19:21","date_gmt":"2018-11-02T03:19:21","guid":{"rendered":"http:\/\/zewwy.ca\/?p=442"},"modified":"2018-11-01T22:19:38","modified_gmt":"2018-11-02T03:19:38","slug":"iis-redirect-http-to-https","status":"publish","type":"post","link":"https:\/\/zewwy.ca\/index.php\/2018\/11\/01\/iis-redirect-http-to-https\/","title":{"rendered":"IIS redirect HTTP to HTTPS"},"content":{"rendered":"<h1 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"The_Requirement\"><\/span>The Requirement<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Recently I <a href=\"http:\/\/zewwy.ca\/index.php\/2018\/02\/14\/creating-requesting-approving-installing-certificates-on-iis-core\/\">posted about creating and using a certificate for use on and IIS website<\/a>. I did this recently for my Dev to deploy his new web app, which required use of a devices camera for QR scanning purposes, well it runed out that the camera could not be used unless the app was secured with TLS (a certificate). So we created a cert and created a new secure binding.<\/p>\n<p>However, it was soon pretty apparent every time I pressed the down arrow key on my browsers URL it would use the regular HTTP (at first we removed the port 80 binding which caused site unavailable issue). So after re-adding the standard port 80 binding for regular HTTP, I decided to use a rewrite rule to handle the redirection.<\/p>\n<p>It wasn&#8217;t as intuitive as I thought it would be <a href=\"https:\/\/www.namecheap.com\/support\/knowledgebase\/article.aspx\/9953\/38\/setting-up-an-httphttps-redirect-in-iis\">so a little google search<\/a> and I was on my way&#8230;<\/p>\n<p>As the source states, after you have your certificate and port binding for HTTPS, as well as one for regular HTTP.<\/p>\n<p>In order to force a secure connection on your website, it is necessary to set up a certain HTTP\/HTTPS redirection rule. This way, anyone who enters your site using a link like \u201cyourdomain.com\u201d will be redirected to \u201chttps:\/\/yourdomain.com\u201d or \u201chttps:\/\/www.yourdomain.com\u201d (depending on your choice) making the traffic encrypted between the server and the client side.<\/p>\n<p>Below you can find the steps for setting up the required redirect:<\/p>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"The_Source\"><\/span>The Source<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li style=\"list-style-type: none\">\n<ol>\n<li><a href=\"http:\/\/www.iis.net\/downloads\/microsoft\/url-rewrite\" target=\"_blank\" rel=\"noopener\">Download and install<\/a> the \u201cURL Rewrite\u201d module.<\/li>\n<li>Open the \u201cIIS Manager\u201d console and select the website you would like to apply the redirection to in the left-side menu:<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/namecheap.simplekb.com\/\/SiteContents\/2-7C22D5236A4543EB827F3BD8936E153E\/media\/iisred1.png\" alt=\"iisred1\" width=\"920\" height=\"460\" border=\"0\" \/><\/li>\n<li>Double-click on the \u201cURL Rewrite\u201d icon.<\/li>\n<li>Click \u201cAdd Rule(s)\u201d in the right-side menu.<\/li>\n<li>Select \u201cBlank Rule\u201d in the \u201cInbound\u201d section, then press \u201cOK\u201d:<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/namecheap.simplekb.com\/\/SiteContents\/2-7C22D5236A4543EB827F3BD8936E153E\/media\/iisred2.png\" alt=\"iisred2\" width=\"576\" height=\"353\" border=\"0\" \/><\/li>\n<li>Enter any rule name you wish.<\/li>\n<li>In the \u201cMatch URL\u201d section:- Select \u201cMatches the Pattern\u201d in the \u201cRequested URL\u201d drop-down menu<br \/>\n&#8211; Select \u201cRegular Expressions\u201d in the \u201cUsing\u201d drop-down menu<br \/>\n&#8211; Enter the following pattern in the \u201cMatch URL\u201d section: \u201c(.*)\u201d<br \/>\n&#8211; Check the \u201cIgnore case\u201d box<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/namecheap.simplekb.com\/\/SiteContents\/2-7C22D5236A4543EB827F3BD8936E153E\/media\/iisred3.png\" alt=\"iisred3\" width=\"705\" height=\"290\" border=\"0\" \/><\/li>\n<li>In the \u201cConditions\u201d section, select \u201cMatch all\u201d under the \u201cLogical Grouping\u201d drop-down menu and press \u201cAdd\u201d.<\/li>\n<li>In the prompted window:<br \/>\n&#8211; Enter \u201c{HTTPS}\u201d as a condition input<br \/>\n&#8211; Select \u201cMatches the Pattern\u201d from the drop-down menu<br \/>\n&#8211; Enter \u201c^OFF$\u201d as a pattern<br \/>\n&#8211; Press \u201cOK\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/namecheap.simplekb.com\/\/SiteContents\/2-7C22D5236A4543EB827F3BD8936E153E\/media\/iisred4.png\" alt=\"iisred4\" width=\"810\" height=\"182\" border=\"0\" \/><\/li>\n<li>In the \u201cAction\u201d section, select \u201cRedirect\u201d as the action type and specify the following for \u201cRedirect URL\u201d:<b>https:\/\/{HTTP_HOST}\/{R:1}<\/b><\/li>\n<li>Check the \u201cAppend query string\u201d box.<\/li>\n<li>Select the Redirection Type of your choice. The whole \u201cAction\u201d section should look like this:<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/namecheap.simplekb.com\/\/SiteContents\/2-7C22D5236A4543EB827F3BD8936E153E\/media\/iisred5.png\" alt=\"iisred5\" width=\"601\" height=\"237\" border=\"0\" \/><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h1 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"The_Note\"><\/span>The Note<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>NOTE: There are 4 redirect types of the redirect rule that can be selected in that menu:<br \/>\n&#8211; Permanent (301) \u2013 preferable type in this case, which tells clients that the content of the site is permanently moved to the HTTPS version. Good for SEO, as it brings all the traffic to your HTTPS website making a positive effect on its ranking in search engines.<br \/>\n&#8211; Found (302) \u2013 should be used only if you moved the content of certain pages to a new place *temporarily*. This way the SEO traffic goes in favour of the previous content\u2019s location. This option is generally not recommended for a HTTP\/HTTPS redirect.<br \/>\n&#8211; See Other (303) \u2013 specific redirect type for GET requests. Not recommended for HTTP\/HTTPS.<br \/>\n&#8211; Temporary (307) \u2013 HTTP\/1.1 successor of 302 redirect type. Not recommended for HTTP\/HTTPS.<\/p>\n<ol>\n<li>Click on \u201cApply\u201d on the right side of the \u201cActions\u201d menu.<\/li>\n<\/ol>\n<p>The redirect can be checked by accessing your site via http:\/\/ specified in the URL. To make sure that your browser displays not the cached version of your site, you can use anonymous mode of the browser.<\/p>\n<h1 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"The_Helping_Hand\"><\/span>The Helping Hand<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><b>The rule is created in IIS, but the site is still not redirected to https:\/\/<\/b><\/p>\n<p>Normally, the redirection rule gets written into the web.config file located in the document root directory of your website. If the redirection does not work for some reason, make sure that web.config exists and check if it contains the appropriate rule.<\/p>\n<p>To do this, follow these steps:<\/p>\n<ol>\n<li>In the sites list of IIS, right-click on your site. Choose the \u201cExplore\u201d option:<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/namecheap.simplekb.com\/\/SiteContents\/2-7C22D5236A4543EB827F3BD8936E153E\/media\/iisred6.png\" alt=\"iisred6\" width=\"625\" height=\"312\" border=\"0\" \/><\/li>\n<li>\u201cExplore\u201d will open the document root directory of the site. Check if the web.config file is there.<\/li>\n<li>The web.config file must have the following code block:<i><br \/>\n&lt;configuration&gt;<br \/>\n&lt;system.webServer&gt;<br \/>\n&lt;rewrite&gt;<br \/>\n&lt;rules&gt;<br \/>\n&lt;rule name=&#8221;HTTPS force&#8221; enabled=&#8221;true&#8221; stopProcessing=&#8221;true&#8221;&gt;<br \/>\n&lt;match url=&#8221;(.*)&#8221; \/&gt;<br \/>\n&lt;conditions&gt;<br \/>\n&lt;add input=&#8221;{HTTPS}&#8221; pattern=&#8221;^OFF$&#8221; \/&gt;<br \/>\n&lt;\/conditions&gt;<br \/>\n&lt;action type=&#8221;Redirect&#8221; url=&#8221;https:\/\/{HTTP_HOST}\/{R:1}&#8221; redirectType=&#8221;Permanent&#8221; \/&gt;<br \/>\n&lt;\/rule&gt;<br \/>\n&lt;\/rules&gt;<br \/>\n&lt;\/rewrite&gt;<br \/>\n&lt;\/system.webServer&gt;<br \/>\n&lt;\/configuration&gt;<\/i><\/li>\n<li>If the web.config file is missing, you can create a new .txt file, put the aforementioned code there, save and then rename the file to web.config.<\/li>\n<\/ol>\n<p>This one, much like my Offline Root CA post is a direct copy of the source. For the same reason, I felt I had no need to re-word it as it was very well written.<\/p>\n<p>Thanks Namecheap, although it would have been nice to thank the actual author who took the time to do the beautiful write up with snippets. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Requirement Recently I posted about creating and using a certificate for use on and IIS website. I did this recently for my Dev to deploy his new web app, which required use of a devices camera for QR scanning purposes, well it runed out that the camera could not be used unless the app &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/zewwy.ca\/index.php\/2018\/11\/01\/iis-redirect-http-to-https\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;IIS redirect HTTP to HTTPS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","footnotes":""},"categories":[8],"tags":[120,121,22,122],"class_list":["post-442","post","type-post","status-publish","format-standard","hentry","category-server-administration","tag-http","tag-https","tag-iis","tag-redirect"],"_links":{"self":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/comments?post=442"}],"version-history":[{"count":1,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/442\/revisions"}],"predecessor-version":[{"id":443,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/442\/revisions\/443"}],"wp:attachment":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/media?parent=442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/categories?post=442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/tags?post=442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}