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:
you'll need to do the following:
- Open IIS, right click on the desired website and select "properties"
- Select the "Home Directory" tab
- Select the "A redirection to a URL" option
- Enter http://AppName.CompanyName.com, followed by $V$Q
- $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
- $Q passes the querystring, including the question mark
- Check the "The exact URL entered above" option
- 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.
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.
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.
|$S||Passes 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.|
|$P||Passes 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.|
|$Q||Passes 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.|
|$V||Passes 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 $9||Passes 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.|
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:
When you use wildcard characters, be sure to select The exact URL entered above check box. For a redirected path, type in a URL.