Recipe12.14.Configuring Web Site Redirection


Recipe 12.14. Configuring Web Site Redirection

Problem

You want to redirect requests for files in your web site to a different site, directory, or file.

Solution

Using a graphical user interface

To redirect requests to files in your web site's home directory, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the console tree to display your web site, right-click on the site, and select Properties.

  3. Select the Home Directory tab.

  4. Select the option named A redirection to a URL.

  5. Select the option The exact URL entered above, if you want to redirect requests to a specific file. For example, type /temp/default.htm in the Redirect to box if you want to redirect requests for files in your home directory to the default.htm file in the /temp virtual directory.

  6. Select the option A directory below URL entered, if you want to redirect requests to files in a subdirectory. For example, type /newsite in the Redirect to box if you want to redirect requests for files in your home directory to a new version of your site in the /newsite subdirectory.

  7. Select the option A permanent redirection for this resource, if you want to send an "HTTP 301 Permanent Redirect" status message to clients requesting files from your home directory.

To redirect requests to files in a virtual directory, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the console tree to display your web site, right-click on a virtual directory, and select Properties.

  3. Select the Virtual Directory tab.

  4. Follow steps 5 through 7 above.

To redirect requests to a particular file, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the console tree to display your web site, right-click on a particular file, and select Properties.

  3. Select the File tab.

  4. Select the option The exact URL entered above and specify the full URL of the file you want to redirect to.

Using VBScript
' This code creates a redirect for a virtual directory ' and maintains the path info during redirection ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" ' ------ END CONFIGURATION ---------  set objVirtualDir = GetObject("IIS://" & strComputer & "/W3SVC/1/Root/CGIs") objVirtualDir.Put "HttpRedirect", _                   "http://www.rallencorp.com/NewSite/CGIs$S$Q, EXACT_DESTINATION" objVirtualDir.SetInfo WScript.Echo "Redirect set for virtual directory" ' This code creates permanent redirect for an entire web site ' and does NOT maintain path info during redirection ' ------ SCRIPT CONFIGURATION ------ strComputer = "<ServerName>" ' ------ END CONFIGURATION ---------  set objWS = GetObject("IIS://" & strComputer & "/W3SVC/222/Root") objWS.Put "HttpRedirect", _           "http://www.rallencorp.com/newsite, PERMANENT & EXACT_DESTINATION" objWS.SetInfo WScript.Echo "Redirect set for web site"

Discussion

Redirection is useful when you are reorganizing your web site by moving content around or creating a new version of your site. If you fail to configure redirection in such situations, users will experience frustrating "HTTP 404 File Not Found" error messages when visiting bookmarked pages.

Using VBScript

The HttpRedirect metabase property is very flexible. It can be configured to redirect based on a variety of criteria. For the complete list of options available for this property, see the HttpRedirect page in MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_mb_httpredirect.asp).

See Also

MS KB 298498 (IIS generates courtesy redirect when folder without trailing slash is requested)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net