{"id":1898,"date":"2017-01-24T19:44:10","date_gmt":"2017-01-24T19:44:10","guid":{"rendered":"http:\/\/obieta.com\/?p=1898"},"modified":"2017-01-24T19:44:10","modified_gmt":"2017-01-24T19:44:10","slug":"automatically-redirect-http-requests-to-https-on-iis-7-using-url-rewrite-2-0","status":"publish","type":"post","link":"http:\/\/obieta.com\/?p=1898","title":{"rendered":"Automatically Redirect HTTP requests to HTTPS on IIS 7 using URL Rewrite 2.0"},"content":{"rendered":"<p>In a previous article I covered the installation URL Rewrite 2.0 for IIS 7. This is a plug-in for IIS 7 that allows you to manipulate URL\u2019s.<\/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>\u2013 SSL Certificate for site installed in IIS.<br \/>\n\u2013 Site properly installed and configured for SSL (site set up and binding in IIS configured).<br \/>\n\u2013 URL Rewrite 2.0 is installed on the sever.<\/p>\n<h2>GUI Version<\/h2>\n<p>\u2013 Select the website you wish to configure<br \/>\n\u2013 In the \u201cFeatures View\u201d panel, double click URL Rewrite<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical1.png\" alt=\"\" \/><\/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<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical2.png\" alt=\"\" \/><\/p>\n<p>Use the default \u201cBlank rule\u201d and press \u201cOK\u201d.<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical3.png\" alt=\"\" \/><\/p>\n<p>When editing a rule there are the \u201cName\u201d field and 4 configuration pull down boxes.<\/p>\n<p>\u2013 Enter \u201cRedirect to HTTPS\u201d in the name field.<br \/>\n\u2013 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><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical4.png\" alt=\"\" \/><\/p>\n<p>Within the \u201cMatch URL\u201d configuration box we will set the following settings:<\/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><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical5.png\" alt=\"\" \/><\/p>\n<p>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.<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical6.png\" alt=\"\" \/><\/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<img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical7.png\" alt=\"\" \/><\/p>\n<p>You should see your condition in the list of conditions.<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical8.png\" alt=\"\" \/><\/p>\n<p>For this setting we do not need to configure the \u201cServer Variables\u201d pull down box. Continue onto the \u201cAction\u201d configuration box and pull down the box by selecting the arrow on the right. We will configure the following settings for the \u201cAction\u201d configuration:<\/p>\n<p><strong>Action Type<\/strong>: Redirect<br \/>\n<strong>Redirect URL<\/strong>: <a class=\"ext-link\" href=\"http:\/\/www.jppinto.com\/external.php?url=https%3A%2F%2F%7BHTTP_HOST%7D%2F%7BR%3A1\" rel=\"external nofollow\">https:\/\/{HTTP_HOST}\/{R:1<\/a>}<br \/>\n<strong>Redirect Type<\/strong>: See Other (303)<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical9.png\" alt=\"\" \/><\/p>\n<p>Press \u201cApply\u201d then press \u201cBack to Rules\u201d<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical10.png\" alt=\"\" \/><\/p>\n<p>You should now see the rule configured on the main screen of the URL Rewrite module.<\/p>\n<p><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical11.png\" alt=\"\" \/><\/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><img src=\"http:\/\/www.jppinto.com\/wp-content\/uploads\/2010\/03\/031010_2252_Automatical12.png\" alt=\"\" \/><\/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<div>\n<div id=\"highlighter_21136\" class=\"syntaxhighlighter  xml\">\n<div class=\"toolbar\"><a class=\"toolbar_item command_help help\" href=\"http:\/\/www.jppinto.com\/2010\/03\/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0\/#\">?<\/a><\/div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">rule<\/code> <code class=\"xml color1\">name<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"Redirect to HTTPS\"<\/code> <code class=\"xml color1\">stopProcessing<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"true\"<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">match<\/code> <code class=\"xml color1\">url<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"(.*)\"<\/code> <code class=\"xml plain\">\/&gt;<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">conditions<\/code><code class=\"xml plain\">&gt;&lt;<\/code><code class=\"xml keyword\">add<\/code> <code class=\"xml color1\">input<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"{HTTPS}\"<\/code> <code class=\"xml color1\">pattern<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"^OFF$\"<\/code> <code class=\"xml plain\">\/&gt;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">conditions<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"xml plain\">&lt;<\/code><code class=\"xml keyword\">action<\/code> <code class=\"xml color1\">type<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"Redirect\"<\/code> <code class=\"xml color1\">url<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"<a href=\"https:\">https:\/\/<\/a>{HTTP_HOST}\/{R:1}\"<\/code> <code class=\"xml color1\">redirectType<\/code><code class=\"xml plain\">=<\/code><code class=\"xml string\">\"SeeOther\"<\/code> <code class=\"xml plain\">\/&gt;<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"xml plain\">&lt;\/<\/code><code class=\"xml keyword\">rule<\/code><code class=\"xml plain\">&gt;<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>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. Instead use \/images\/logo.jpg.<\/p>\n<p>Credits goes to:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"r0Ga19zwvG\"><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 IIS 7 using URL Rewrite 2.0<\/a><\/p><\/blockquote>\n<p><iframe title=\"&#8220;Automatically Redirect HTTP requests to HTTPS on IIS 7 using URL Rewrite 2.0&#8221; &#8212; JPPinto.com - Tech Blog\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.jppinto.com\/2010\/03\/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0\/embed\/#?secret=r0Ga19zwvG\" data-secret=\"r0Ga19zwvG\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a previous article I covered the installation URL Rewrite 2.0 for IIS 7. This is a plug-in for IIS 7 that allows you to manipulate URL\u2019s. 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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts\/1898"}],"collection":[{"href":"http:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1898"}],"version-history":[{"count":0,"href":"http:\/\/obieta.com\/index.php?rest_route=\/wp\/v2\/posts\/1898\/revisions"}],"wp:attachment":[{"href":"http:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1898"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/obieta.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}