Redirecting Requests to Files, Directories, or Programs (IIS 6.0)
You can redirect requests for files in one directory to a different directory, to a different Web site, or to a file in a different directory. When the browser requests the file from the original URL, the Web server instructs the browser to request the page from the redirected URL.

An advanced capability of the redirect method allows you to redirect all requests for files in a particular directory to a program. Generally speaking, you should also pass any parameters from the original URL to the program, which you can do by using redirect variables.

iis redirect Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /User:Administrative_AccountName“mmc %systemroot%system32inetsrviis.msc”.

>Procedures

To redirect requests to another directory or Web site

1.

In IIS Manager, expand the local computer, right-click the Web site, virtual directory, or directory within a Web site to which you want to add a redirect, and click Properties.

2.

Click the Home Directory, Virtual Directory, or Directory tab.

3.

Under The content for this resource should come from, click A redirection to a URL.

4.

In the Redirect tobox, type the path to the destination directory or the URL of the Web site. For example, to redirect all requests for files in the /Catalog directory to the /NewCatalog directory on another Web site, type http://sitename/NewCatalog. The redirect must be to a fully qualified URL.

5.

Set the required flags as specified below, and then click OK. More than one flag is allowed.

To redirect all requests to a single file

1. In IIS Manager, right-click the Web site or directory, and click Properties.

2.

Click the Home Directory, Virtual Directory, or Directory tab.
3. Under The content for this resource should come from, click A redirection to a URL.
4. In the Redirect to box, type the URL of the destination file. The redirect must be to a fully qualified URL.
5. Under The client will be sent to, select The exact URL entered above check box to prevent the Web server from appending the original file name to the destination URL.

6.

Click OK.

You can use wildcards and redirect variables in the destination URL to precisely control how the original URL is translated into the destination URL.

To redirect requests to a program

1. In IIS Manager, right-click the Web site or directory, and click Properties.
2. Click the Home Directory, Virtual Directory, or Directory tab.
3. Under The content for this resource should come from, click A redirection to a URL.
4. In the Redirect to box, type the URL of the program, including any redirect variables needed to pass parameters to the program.For example, to redirect all requests for scripts in a Scripts directory to a logging program that records the requested URL and any parameters passed with the URL, type /Scripts/Logger.exe?URL=$V+PARAMS=$P. $V and $P are redirect variables.
5. Under The client will be sent to, select The exact URL entered above check box to prevent the Web server from appending the original file name to the destination URL.
6. Click OK.

Redirect Reference (IIS 6.0)

Redirecting a client 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 to a different URL.


H3>Configuring URL and Wildcard Redirection

You can configure redirection to a URL and wildcard redirection programmatically. Redirection variables and flags allow you to specify targets and behavior by changing the HttpRedirectmetabase property.

The following example shows the format of a simple redirection string.

http://DestinationURL[,Flag[s]]

Where DestinationURL can include the following redirect variables to pass portions of the original URL with the destination URL. You can use more than one variable in a single redirection string.

Variable Description Example

$S

Passes the suffix of the requested URL to the new URL. The suffix is the portion of the original URL that remains after the redirected URL is substituted.

If the EXACT_DESTINATION flag is not set, the resulting destination URL will have the name of the requested file appended as a folder name, as well as the file name itself.

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following exact URL:

http://fabrikam/NewScripts$S

A new request for the following URL:

http://fabrikam/Scripts/Program.exe

Would be redirected automatically to the following URL:

http://fabrikam/NewScripts/Program.exe

$P

Passes parameters (such as querystring parameters) in the original URL to the new URL, without the question mark (?).

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following URL:

http://fabrikam/NewScripts$P

A new request for the following URL:

http://fabrikam/Scripts/File.asp?var1=5&var2=6

Would be redirected automatically to the following URL:

http://fabrikam/NewScriptsvar1=5&var2=6

$Q

Passes parameters (such as querystring parameters) in the original URL to the new URL, including the question mark (?).

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following exact URL:

http://fabrikam/NewScripts$S$Q

A new request for the following URL:

http://fabrikam/Scripts/File.asp?var1=5&var2=6

Would be redirected automatically to the following URL:

http://fabrikam/NewScripts/File.asp?var1=5&var2=6

$V

Passes the requested URL, without the server name and without any parameters. To include parameters, use the $P or $Q variable with the $V variable.

If the EXACT_DESTINATION flag is not set, the resulting destination URL will have the name of the requested file appended as a folder name, as well as the file name itself.

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected to the following exact URL:

http://contoso$V

A new request for the following URL:

http://fabrikam/Scripts/File.asp

Would be redirected automatically to the following URL:

http://contoso/Scripts/File.asp

Redirection Using Wildcards

You can use redirect wildcards to match any number of characters in the original URL. Begin the destination URL with an asterisk (*) and a semicolon (;), and separate pairs of wildcard characters and destination URLs with a semicolon. The following example shows the format of a redirection string that uses wildcards.

*; Wildcard1; Destination1[; Wildcard2; Destination2][, Flags]

Where WildcardN can include an asterisk (*) to match any number of characters in the original URL and pass them to DestinationN by using the $0 through $9 variables defined in the following table.

“Variable” “Description” “Example”
$0 through $9 Passes the portion of the requested URL that matches the indicted wildcard character. Wildcards must start at $0 for each Wildcard;Destination set. The EXACT_DESTINATION flag must be appended to the redirection string. If the virtual directory that is mapped to the following Web site:http://fabrikam/Scriptsis configured with the following redirection string:*; /Scripts/*_in.asp; /NewScripts/$0.dll; /Scripts/*_out.asp; http://contoso/NewScripts/$0.dllA new request for the following URLs:http://fabrikam/Scripts/data_in.asphttp://fabrikam/Scripts/data_out.aspWould be redirected automatically to the following respective URLs:http://fabrikam/NewScripts/data.dll

http://contoso/NewScripts/data.dll

!

Does not allow a redirect.

This variable is useful when you want to exempt files or subdirectories from redirection when a parent directory is configured to be redirected.

If the virtual directory that is mapped to the following Web site:

http://fabrikam/Scripts

is configured to be redirected, but the following Web site:

http://fabrikam/Scripts/Commerce/Accounts

needs to be exempt, programmatically set the redirection string for the exempted folder to the following

*;!

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, use the following redirect request for the /Scripts virtual directory:

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

Using Redirection Flags

The following flags augment redirect strings of either URL or wildcard format. More than one flag is allowed. Flags are appended programmatically to the redirection string in HttpRedirect, or configured by selecting check boxes in IIS Manager.

Flag User Interface Check Box Description
EXACT_DESTINATION The exact URL entered above Indicates that the value provided for the destination should be considered an absolute target location.
CHILD_ONLY A directory below this one Alerts IIS that redirection should occur only once because the destination is in a subdirectory of the original URL. This flag avoids loops. Also, this flag instructs IIS to redirect requests only if they are to subfolders or files of the original URL.
PERMANENT A permanent redirection for this resource Indicates that this redirection is permanent for this resource.
TEMPORARY Clear the A permanent redirection for this resource check box” Indicates that this redirection is temporary for this resource.

How to Move Pages on Windows Servers

Most Windows servers will be running Microsoft’s Internet Information Server (IIS), and pages can be moved using ASP or ASP.NET code, depending on what the server is running (ask your web host). To move a page using ASP, set up the page at its new location then place the following code at the top of the old page:

Move a page using ASP
<%@ Language=VBScript %>
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.domain.com/new-page.asp”
%>

Make sure that code is the first thing at the top of the page. As for the rest of the page, you can either remove its content or leave it—search engines won’t care one way or another. However, some of your human visitors (remember them?) will have auto-redirection turned off in their browsers.

This means they won’t be redirected, and will see the old page instead of the new one. So you may want to include a link to the new page, along with a short message telling them that the page they’re on is outdated and has been moved to a new location.

Similarly, you can move a page using ASP.NET, but beware there’s currently a glitch in the way ASP.NET 2 handles redirects. That glitch should be fixed soon. To redirect a page using ASP.NET, set up the new page at its new location, then place the following code at the top of the old page:
<script runat=”server”>
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(“Location”,”http://www.domain.com/new-page.asp”);
}
</script>

For both of these redirects leave the old pages in place for as long as possible, since it usually takes several months for search engines to switch over to only crawling the page at its new location. They’re a bit slow that way.

Get Found Now – a division of: On Top Of It, Inc