IIS Configuration - HTTP Redirect

From Hostek.com Wiki
Revision as of 17:09, 21 June 2013 by Davidd (Talk | contribs) (Created page with "This article explains how to use the HTTP Redirect section in IIS 7 and above. ==What is it for== The HTTP Redirect section is used to do one of the following: *Redirect a ...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article explains how to use the HTTP Redirect section in IIS 7 and above.

What is it for

The HTTP Redirect section is used to do one of the following:

  • Redirect a file to a different file, to a different folder, or to a different site.
  • Redirect a directory to a file within a different directory, to a different directory, or to a different site.
  • Redirect a site to a different site

Bottom line, if you have content that has been moved, and you want to redirect users to the new location of the content, this is a good tool to use.

What it is not for

The HTTP Redirect section is not ideal for doing any of the following:

For all of the above, the proper tool to use is "IIS Rewrite" or "ISAPI_Rewrite"

Configuring through IIS Manager GUI

How to configure HTTP Redirects directly through the IIS Manager GUI.

  • Within IIS Manager, choose the specific site, directory, or file you would like to redirect using the 'Sites' tree-menu. For selecting files, you will need to choose the containing folder, select 'Content View' toward the bottom of the window, select the specific file, and click 'Switch to Features View' .
  • Choose HTTP Redirect
  • Configure the following options:

  • Redirect requests to this destination
    • Checking this option enables the HTTP Redirect
  • Destination Box (The text box immediately below the above option)
    • Allows you to specify the destination of the redirect

Redirect Behavior:

  • Redirect all requests to the exact destination (instead of relative to destination)
    • When this option is checked, browsers will be redirect to the exact URL that was entered in the 'Destination Box' regardless of the original URL.
    • When this option is unchecked, the relative path underneath the redirected site or folder will be maintained at the destination.
  • Only redirect requests to content in this directory (not subdirectories)
    • Checking this option when setting the redirect on a directory will only redirect traffic within the specific directory. Traffic going to sub-directories will not be redirected.
    • Leaving this option unchecked will redirect both the current directory and all sub-directories.
  • Status Code
    • Found (302) - Use this option if the redirect is only temporary. Browsers will not cache the redirect and search engines will continue attempting to index the source.
    • Permanent (301) - Use this option if the redirect is permanent. Browsers will cache the redirect and search engines will stop indexing the source and index the destination instead.
    • Temporary (307) - Use this option if the redirect is only temporary, and you want POST data to be redirected to the destination.

  • Click 'Apply' .

Configuring directly in web.config file

On shared servers, you may not have access to the IIS Manager GUI. In these cases, you can configure the redirect within the control panel (IIS Settings => URL Forwarding) or by directory creating/modifying a web.config file on your site. Below is how to configure the web.config file:

The following is an example of the 'httpRedirect' configuration section:

<configuration>
  <system.webServer>
    <httpRedirect enabled="true" destination="http://www.domainname.com/" exactDestination="false" httpResponseStatus="Permanent" />
  </system.webServer>
</configuration>

The options are the same as those when using the GUI to configure the redirect (see GUI details above). If you want the section to affect only a particular file or sub-directory, use the 'location' tag to specify the location that this configuration section should affect. Example:

<configuration>
  <location path="OldPage.html">
    <system.webServer>
      <httpRedirect enabled="true" destination="NewPage.html" exactDestination="true" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>
</configuration>



Davidd (talk) 12:09, 21 June 2013 (CDT)