{"id":153,"date":"2007-05-09T18:11:18","date_gmt":"2007-05-10T00:11:18","guid":{"rendered":"http:\/\/jameskovacs.com\/2007\/05\/10\/How+To+AutoRedirect+To+A+SSLsecured+Site+In+IIS"},"modified":"2007-05-09T18:11:18","modified_gmt":"2007-05-10T00:11:18","slug":"how-to-autoredirect-to-a-sslsecured-site-in-iis","status":"publish","type":"post","link":"https:\/\/www.jameskovacs.com\/index.php\/2007\/05\/09\/how-to-autoredirect-to-a-sslsecured-site-in-iis\/","title":{"rendered":"How to Auto-Redirect to a SSL-secured Site in IIS"},"content":{"rendered":"<p>I was recently asked how to configure a site to redirect automatically from HTTP to HTTPS. By this\u00a0I mean when the user types in <a href=\"http:\/\/server.example.com\/app\/page.aspx\">http:\/\/server.example.com\/app\/page.aspx<\/a>,* the browser will automatically redirect to <a href=\"https:\/\/server.example.com\/app\/page.aspx\">https:\/\/server.example.com\/app\/page.aspx<\/a>.\u00a0You can do it through code, but with a little ingenuity, you can do it strictly through IIS configuration. Let&#8217;s walk through the setup&#8230;<\/p>\n<p>Open IIS Manager and select properties for the website for which you want to require SSL. For TCP port, enter any unused port other than port 80 (the default HTTP port). For example, use 8888. For SSL port,\u00a0enter the default SSL port, which is 443. Now go to the Directory Security tab&#8230; Secure\u00a0communications&#8230; Edit&#8230;\u00a0Set the &#8220;Require secure channel (SSL)&#8221; (required) and &#8220;Require 128-bit encryption&#8221; (optional, but recommended). Restart IIS. Browse to <a href=\"http:\/\/server.example.com:8888\/\">http:\/\/server.example.com:8888<\/a> now and\u00a0you will get &#8220;The page must be viewed over a secure channel&#8221;. So far, so good.<\/p>\n<p>Create a brand new IIS website by right-clicking&#8230; New&#8230; Web site&#8230;\u00a0Click Next and give the website a name such as &#8220;Redirect to SSL&#8221;. Click Next&#8230; For TCP port, choose port 80, the default HTTP port. For path, point it to c:\\inetpub\\wwwroot. (It doesn&#8217;t really matter as we&#8217;ll be changing this in a minute.) Click Next&#8230; Give it Read permissions. Click Next&#8230;\u00a0Finish&#8230; to create the website. Right-click, properties on the new website. Select the Home Directory tab. Change &#8220;The content for this resource should come from:&#8221; to &#8220;A redirection to a URL&#8221;. In the &#8220;Redirect to:&#8221; textbox, enter <a href=\"https:\/\/server.example.com\/\">https:\/\/server.example.com<\/a>. You can also optionally select &#8220;A permanent redirection for this resource&#8221;, which will cause bookmarks to update to the new URL. DO NOT, I repeat, DO NOT select &#8220;The exact URL entered above&#8221; or &#8220;A directory below URL entered&#8221;. Restart IIS. Now browse to <a href=\"http:\/\/server.example.com\/\">http:\/\/server.example.com<\/a> and you&#8217;ll be redirected to the SSL site. Note that the path portion of the URL is preserved and only the protocol and server are modified. So <a href=\"http:\/\/server.example.com\/some\/path\/deep\/within\/my\/app.aspx\">http:\/\/server.example.com\/some\/path\/deep\/within\/my\/app.aspx<\/a> will redirect to <a href=\"https:\/\/server.example.com\/some\/path\/deep\/within\/my\/app.aspx\">https:\/\/server.example.com\/some\/path\/deep\/within\/my\/app.aspx<\/a> just by applying the redirection steps noted above.<\/p>\n<p>N.B. The redirect URL is sent back to the client. So if you type <a href=\"https:\/\/localhost\/\">https:\/\/localhost<\/a> as the redirect, the client browser will try to redirect to localhost on the client&#8217;s machine, which probably won&#8217;t exist. Same thing goes for NetBIOS names. (e.g. <a href=\"https:\/\/server\/\">https:\/\/server<\/a> rather than <a href=\"https:\/\/server.example.com\/\">https:\/\/server.example.com<\/a>)<\/p>\n<p>* Little known fact. Example.com, example.net, and example.org are reserved top level DNS names as specified in <a href=\"http:\/\/www.rfc-editor.org\/rfc\/rfc2606.txt\">RFC 2606<\/a>, Section 3 and are intended for &#8211; surprise,\u00a0surprise &#8211; examples. This allows authors to create bogus URLs in books, blog posts, and elsewhere that are guaranteed to go nowhere, which is generally the author&#8217;s intent when creating a bogus URL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently asked how to configure a site to redirect automatically from HTTP to HTTPS. By this\u00a0I mean when the user types in http:\/\/server.example.com\/app\/page.aspx,* the browser will automatically redirect to https:\/\/server.example.com\/app\/page.aspx.\u00a0You can do it through code, but with a little ingenuity, you can do it strictly through IIS configuration. Let&#8217;s walk through the setup&#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,21],"tags":[],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-aspnet","category-security"],"_links":{"self":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":0,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}