JURASOURCE | WEBLOG | |
 

 

Like, uh, whatever, I guess

 

 
  Monday, April 19, 2004
 
    [3:20:46 PM]

Advanced IIS 6 Redirector


IIS's ability to redirect a request to another URL is extremley useful, for example when moving or renaming an application.  For one thing it doesn't cause users that have bookmarked the old URL to see a "page not found" error.


Generally this isn't a tricky operation, but when you need to worry about preserving the request URL's structure, and it's querystring, you need to start playing around with the IIS redirect parameters.


So, to redirect all requests to a URL like:



http://AppName/Dir1/Dir2/Page.aspx?param1=value1&param2=value2 


to



http://AppName.CompanyName.com/Dir1/Dir2/Page.aspx?param1=value1&param2=value2 


you'll need to do the following:



  1. Open IIS, right click on the desired website and select "properties"
  2. Select the "Home Directory" tab
  3. Select the "A redirection to a URL" option
  4. Enter http://AppName.CompanyName.com, followed by $V$Q

    1. $V passes the URL without the server name, in this instance "Dir1/Dir2/Page.aspx", if you want to redirect to a different directory, use: http://AppName.CompanyName.com/NewDir1/Page.aspx$Q
    2. $Q passes the querystring, including the question mark

  5. Check the "The exact URL entered above" option
  6. Click Apply and you're ready to rock.

I've included the entire IIS Administration help page on this topic, I would just point you towards a page on MSDN, but the one they have just results in a 404.


Redirect Reference


Redirecting a client's request is one way to ensure that users get the correct page, if your site is under construction or has changed identity. You can redirect client requests to a directory on the same Web server or a different URL.


Redirect Variables


You can use redirect variables to pass portions of the original URL with the destination URL. To use these variables, open a directory's properties in IIS Manager, select the Home Directory, Virtual Directory, or Directory tab, click the A redirection to a URL option, and enter a URL in the Redirect to text box, using any of the variables below.
































VariableDescriptionExample
$SPasses the matched suffix of the requested URL. The matched suffix is the portion of the original URL that remains after the redirected URL is substituted.If /Scripts is redirected to /Newscripts, and the original request is for /Scripts/Program.exe, /Program.exe is the suffix. The server automatically substitutes this suffix; you use the $S variable only in combination with other variables.
$PPasses the parameters in the original URL.For example, if the original URL is /Scripts/Myscript.asp?number=1, the string "number=1" is mapped to the destination URL.
$QPasses both the question mark (?) and the parameters from the original URL.For example, if the original URL is /Scripts/Myscript.asp?number=1, the string "?number=1" is mapped to the destination URL.
$VPasses the requested URL, without the server name.For example, if the original URL is //Myserver/Scripts/Myscript.asp, the string "/Scripts/Myscript.asp" is mapped to the destination URL.
$0 through $9Passes the portion of the requested URL that matches the indicated wildcard character.For example, if a wildcard character is used for the lowest-level directory name, such as */Default.htm, the part of the URL that names the directory containing Default.htm is passed.
!Do not redirect.Use this variable to prevent redirecting a subdirectory or an individual file in a virtual directory that has been redirected.


Redirect Wildcards


You can use redirect wildcards to match any number of characters in the original URL. Open a directory's property sheet in IIS Manager, select the Home Directory, Virtual Directory, or Directory tab, click the A redirection to a URL option, and insert the wildcard character (*) in the Redirect to text box. Begin the destination URL with an asterisk (*) and a semicolon (;), and separate pairs of wildcard characters and destination URLs with a semicolon.


For example, to redirect all requests for /Scripts/Filename.stm to a single file called Default.stm, and to redirect all requests for /Scripts/Filename.htm to a single file called Default.htm, type the following in the Redirect To text box for the /scripts virtual directory:


*;Filename.stm;/Default.stm;Filename.htm;/Default.htm


When you use wildcard characters, be sure to select The exact URL entered above check box. For a redirected path, type in a URL.

    |
 
 


ARCHIVES
 
November 2003
January 2004
February 2004
March 2004
April 2004
May 2004
June 2004
 
     

This page is powered by Blogger. Isn't yours?  Weblog Commenting and Trackback by HaloScan.com