{"id":866,"date":"2012-10-03T21:25:36","date_gmt":"2012-10-03T21:25:36","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=866"},"modified":"2012-10-03T21:25:36","modified_gmt":"2012-10-03T21:25:36","slug":"http-redirection-in-iis-7-on-windows-server-2008","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=866","title":{"rendered":"HTTP Redirection in IIS 7 on Windows Server 2008"},"content":{"rendered":"<p>If you have a website and want to change domain names or if you need  to change the architecture of your site, you won\u2019t want visitors  following links from other sites and search engines such as Google to  get an error while visiting your website. This can cause visitors to  click away and a loss of rankings in the search engines.<\/p>\n<p>Luckily there is a fairly simple and straightforward way to remedy  the situation through the use of redirects. First, let\u2019s look at the  different types of redirects that are available in IIS 7:<\/p>\n<ul>\n<li><strong>301 \u2013 Permanent:<\/strong> This redirect tells the Web client that the location of the requested resource has moved permanently<\/li>\n<li><strong>302 \u2013 Standard:<\/strong> This redirect tells the Web client to issue a new request to the location specified<\/li>\n<li><strong>307 \u2013 Temporary:<\/strong> This redirect tells the Web client  to resend POST data, which prevents a Web browser from losing data when  the browser issues an HTTP POST request<\/li>\n<\/ul>\n<p>In most circumstances you will want to use a 301 redirect, as this  will inform search engines to update their index with the resource\u2019s new  location.  In some cases a 302 will be appropriate if the change is  going to be short term such as a special page that is seasonal.<\/p>\n<p>For this article I will assume that you already have a site setup on a  Windows Server 2008 system setup in a web server role, and are familiar  with getting into IIS manager.<\/p>\n<h2>Redirect to a Different URL<\/h2>\n<p>The first and most simple of the redirects will go from one domain to  another, useful if you are changing domain names. I have setup the  following two domains <strong>TSOriginal.com<\/strong> and <strong>TSRedirect.com<\/strong> on my test server as you can see:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 1\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect01.png\" border=\"0\" alt=\"IIS 7 Redirection - 1\" width=\"500\" height=\"375\" align=\"middle\" \/><\/p>\n<p>As you can see, we setup the original domain as <strong>TSOriginal.com<\/strong> and have put a simple index.html file in place that looks like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 2\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect02.png\" border=\"0\" alt=\"IIS 7 Redirection - 2\" width=\"500\" height=\"389\" align=\"middle\" \/><\/p>\n<p>Now let\u2019s walk through the steps required to setup a redirect to our target domain <strong>TSRedirect.com<\/strong>.  If it works correctly then we should see the new index.html page below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 3\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect03.png\" border=\"0\" alt=\"IIS 7 Redirection - 3\" width=\"500\" height=\"390\" align=\"middle\" \/><\/p>\n<p><strong>1. <\/strong> Open IIS Manager by going to <strong>Start -&gt; Administrative Tools -&gt; IIS Manager<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 4\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect05.png\" border=\"0\" alt=\"IIS 7 Redirection - 4\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>2. <\/strong> Once IIS Manager opens, expand the WebServer, then the <strong>Sites<\/strong> folder, and choose the domain, in this case <strong>TSOriginal.com<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 5\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect06.png\" border=\"0\" alt=\"IIS 7 Redirection - 5\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>3. <\/strong> Click on <strong>HTTP REDIRECT<\/strong> in the main panel<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 6\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect07.png\" border=\"0\" alt=\"IIS 7 Redirection - 6\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>4. <\/strong> Place a check next to <strong>Redirect requests to this destination:<\/strong> and fill in the target url in the text box below.  In this instance it will be <strong>TSRedirect.com<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 7\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect08.png\" border=\"0\" alt=\"IIS 7 Redirection - 7\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>5. <\/strong> In the <strong>Redirect Behavior<\/strong> we have several decisions to make about how we want the redirects to work.  Let\u2019s explore each of these options.<\/p>\n<ul>\n<li><strong>Redirect all requests to exact destination<\/strong> \u2013 If  this object is checked all requests no matter what the original  destination will be redirected to the exact location in the text box  above.  If unchecked everything will be redirected relative to the  destination.<\/li>\n<li><strong>Only redirect requests to content in this directory (not subdirectories)<\/strong> \u2013 By default, when you enable redirection, content can be served by  subdirectories below the main directory.  If you choose this option you  can limit requests to just the directory you want without effecting the  subdirectories.<\/li>\n<li><strong>Status Code<\/strong> \u2013 In this drop down you choose which  status code to return when redirecting.  As discussed earlier in this  article your options are <strong>301<\/strong>, <strong>302<\/strong>, and <strong>307<\/strong>.<\/li>\n<\/ul>\n<p><strong>6. <\/strong> For this example we will leave everything unchecked and set a status of <strong>301<\/strong> in the dropdown menu.  Click <strong>Apply<\/strong> to set the options.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 8\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect09.png\" border=\"0\" alt=\"IIS 7 Redirection - 8\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>7. <\/strong> The changes are now in place and if we navigate to TSOriginal.com it will redirect us to TSRedirect.com.<\/p>\n<p>To test if the <strong>301<\/strong> status redirects correctly we  will use the live HTTP headers plugin for Firefox.  It will allow us to  see the status codes.  Here are the results for the test:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 9\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect10.png\" border=\"0\" alt=\"IIS 7 Redirection - 9\" width=\"543\" height=\"362\" align=\"middle\" \/><\/p>\n<p>As you can see from the highlighted area the status was returned 301.<\/p>\n<p>All requests now for TSOriginal.com will be sent to TSRedirect.com with a 301 status code relative to the domain name.<\/p>\n<h2>Redirect a Single Page to Another Page on the Same Site<\/h2>\n<p>This type of redirect is especially useful when you might have some  temporary changes to a webpage because of seasonal or holiday changes.<\/p>\n<p>In the case of a seasonal page that will return to normal after a short time, it is best to use a <strong>302<\/strong> redirect.  This lets search engines and other sites know that this change is expected and not to change their index or links.<\/p>\n<p>For this example we have removed the site redirect we had placed on TSOriginal.com, and added two pages of content to the site:<\/p>\n<p><strong>oldpage.html<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 10\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect11.png\" border=\"0\" alt=\"IIS 7 Redirection - 10\" width=\"501\" height=\"375\" align=\"middle\" \/><\/p>\n<p><strong>newpage.html<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 11\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect12.png\" border=\"0\" alt=\"IIS 7 Redirection - 11\" width=\"501\" height=\"375\" align=\"middle\" \/><\/p>\n<p>Now let\u2019s setup a temporary <strong>302<\/strong> redirect from oldpage.html to newpage.html while.<\/p>\n<p><strong>1. <\/strong> Select the site in IIS manager that you want to set the redirect for.<\/p>\n<p><strong>2. <\/strong> In the Features window switch to <strong>Content View<\/strong>, Right click on the page you want to work with, oldpage.htm in this case, and left click on <strong>Switch to Features View<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 12\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect14.png\" border=\"0\" alt=\"IIS 7 Redirection - 12\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>3. <\/strong> The page now selected in the <strong>Connections Pane<\/strong>, click on <strong>HTTP Redirect<\/strong> in the features pane<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 13\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect15.png\" border=\"0\" alt=\"IIS 7 Redirection - 13\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>4. <\/strong> Check the box next to <strong>Redirect requests to this destination<\/strong>, and fill in the destination page <strong>newpage.htm<\/strong> and set the dropdown menu to <strong>302<\/strong>, and click <strong>Apply<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 14\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect16.png\" border=\"0\" alt=\"IIS 7 Redirection - 14\" width=\"543\" height=\"406\" align=\"middle\" \/><\/p>\n<p><strong>5. <\/strong> Now if we navigate to the page <strong>TSOriginal.com\/oldpage.htm<\/strong> we will be redirected to <strong>TSOriginal.com\/ newpage.htm<\/strong>.<\/p>\n<p>We will again use the Live HTTP Headers plugin for Firefox to view  the redirect.  As you can see the pages redirect with the correct <strong>302<\/strong> status code.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IIS 7 Redirection - 15\" src=\"http:\/\/www.trainsignal.com\/blog\/wp-content\/uploads\/2008\/03\/Dave_IIS7_redirect\/iisredirect17.png\" border=\"0\" alt=\"IIS 7 Redirection - 15\" width=\"543\" height=\"362\" align=\"middle\" \/><\/p>\n<p>You are now ready to do basic redirects in IIS 7 on Windows 2008 server.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a website and want to change domain names or if you need to change the architecture of your site, you won\u2019t want visitors following links from other sites and search engines such as Google to get an error while visiting your website. This can cause visitors to click away and a loss [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-866","post","type-post","status-publish","format-standard","hentry","category-iis-internet-information-services"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=866"}],"version-history":[{"count":1,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/866\/revisions"}],"predecessor-version":[{"id":867,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/866\/revisions\/867"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}