Recipe 12.14. Configuring Web Site RedirectionProblemYou want to redirect requests for files in your web site to a different site, directory, or file. SolutionUsing a graphical user interfaceTo redirect requests to files in your web site's home directory, do the following:
To redirect requests to files in a virtual directory, do the following:
To redirect requests to a particular file, do the following:
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" DiscussionRedirection 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 VBScriptThe 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 AlsoMS KB 298498 (IIS generates courtesy redirect when folder without trailing slash is requested) |