How To Redirect Browser Requests in Internet Information Services 5.0 (313074)



The information in this article applies to:

  • Microsoft Internet Information Services 5.0

This article was previously published under Q313074

SUMMARY

This step-by-step article describes how to redirect browser requests to another folder, a file, a network share, or a program in Internet Information Services (IIS) 5.0.

When a browser requests a page on a Web site, the Web server locates the page that is identified by the uniform resource locator (URL), and then returns it to the browser. If you either move pages, rename virtual directories, or make other changes to your Web content, use IIS to redirect the client computer request to the new location to ensure that browsers can locate a page at the new location. After the browser requests the file at the original URL, IIS instructs the browser to use the new URL to request the page.

You can use IIS to perform any of the following browser redirection procedures:
  • Redirect requests to another folder or Web site.
  • Redirect requests to a file.
  • Redirect requests to a network share.
  • Redirect requests to a program.
You may want to redirect browser requests in any of the following scenarios:
  • Your Web site is still under construction.
  • You update your site and you want to make a portion of your Web site temporarily unavailable.
  • You either rename or delete a virtual directory and you want the hyperlinks in the original virtual directory to access the same files in the new virtual directory.
back to the top

How to Redirect Browser Requests to Another Folder or Web Site

To redirect browser requests to another folder or Web site:
  1. Start Internet Services Manager.

    Alternatively, start the IIS Snap-in in Microsoft Management Console (MMC).
  2. Click to expand * server name, where server name is the name of the server.
  3. Right-click either the Web site or the folder that you want to redirect, and then click Properties.
  4. Click one of the following tabs that is appropriate to your situation:
    • Home Directory
    • Virtual Directory
    • Directory
  5. Under When connecting to this resource, the content should come from, click A redirection to a URL.
  6. Type the URL of the destination folder or Web site in the Redirect to box.

    For example, to redirect all requests for files in the Products folder to the NewProducts folder, type /NewProducts. To redirect all requests for files located at www.mycompany.com/products to sales.mycompany.com/newproducts, type http://sales.mycompany.com/newproducts.
  7. Click OK.
back to the top

How to Redirect Browser Requests to a File

To redirect browser requests to a file:
  1. Start Internet Services Manager.

    Alternatively, start the IIS Snap-in in Microsoft Management Console (MMC).
  2. Click to expand * server name, where server name is the name of the server.
  3. Right-click either the Web site or folder that you want to redirect, and then click Properties.
  4. Click one of the following tabs that is appropriate to your situation:
    • Home Directory
    • Virtual Directory
    • Directory

  5. Under When connecting to this resource, the content should come from, click A redirection to a URL.
  6. Type the URL of the destination file in the Redirect to box.

    For example, to redirect all requests for files in the Products virtual directory to the Default.htm file in the home folder, type /Default.htm.
  7. Under The client will be sent to, click to select the The exact URL entered above check box.
  8. Click OK.
back to the top

How to Redirect Browser Requests to a Network Share

You can use network shares as source folders for Web content by redirecting client requests to the network share. To map a network share:
  1. Start Internet Services Manager.

    Alternatively, start the IIS Snap-in in Microsoft Management Console (MMC).
  2. Click to expand * server name, where server name is the name of the server.
  3. Right-click either the Web site or the folder that you want to redirect, and then click Properties.
  4. Click one of the following tabs that is appropriate to your situation:
    • Home Directory
    • Virtual Directory
    • Directory

  5. Under When connecting to this resource, the content should come from, click A share located on another computer.
  6. Type the UNC path to the network share by using the \\ServerName\ShareName format in the Network Directory box.

    For example, type \\MyServer\MyShare.
  7. Click Connect As, click Browse, click the user account that has permission to access the network share, and then click OK.
  8. Type the password of the user account that you selected, and then click OK.
  9. Click OK.
back to the top

How to Redirect Browser Requests to a Program

If you develop a custom program for your Web site, you can redirect browser requests to the program. To redirect browser requests to a program:
  1. Start Internet Services Manager.

    Alternatively, start the IIS Snap-in in Microsoft Management Console (MMC).
  2. Click to expand * server name, where server name is the name of the server.
  3. Right-click either the Web site or the folder that you want to redirect, and then click Properties.
  4. Click one of the following tabs that is appropriate to your situation:
    • Home Directory
    • Virtual Directory
    • Directory

  5. Under When connecting to this resource, the content should come from, click A redirection to a URL.
  6. Type the URL of the program in the Redirect to box.

    Make sure that you include any redirect variables that are necessary to pass parameters to the program. For example, to redirect all requests for scripts in the Scripts folder to a logging program (Logger.exe) that records the requested URL and any parameters that are passed with the URL, type /Scripts/Logger.exe?URL=$V+PARAMS=$P, where $V and $P are redirection variables.

    For more information about redirect variables, see the Redirect Variables section of this article.
  7. Under The client will be sent to, click to select the The exact URL entered above check box.

    This option redirects the request without appending any portions of the original URL to the destination URL.
  8. Click OK.
back to the top

How to Customize Browser Redirection

When you click A redirection to a URL on either the Home Directory, the Virtual Directory or the Directory tab of the Web site or the folder that you want to redirect, requests for files in the original location are automatically redirected to the destination that you specify in the Redirect to box.

Use any of the following methods to customize how you want to redirect browser requests:
  • Specify URL redirection options.
  • Use redirect variables to pass portions of the original URL with the destination URL.
  • Use redirect wildcards to redirect specific types of files to a particular file.
back to the top

URL Redirection Options

To customize URL redirection, click to select any of the following check boxes under The client will be sent to:
  • The exact URL entered above

    Click to select this check box to redirect a virtual directory to the destination URL without appending a portion of the original URL. Use this setting if you want to redirect a Web site or virtual directory to a single file. For example, to redirect all requests for the Scripts virtual directory to the Default.htm file in the home directory, type /Default.htm in the Redirect to box, and then click to select this check box.
  • A directory below this one

    Click to select this check box to redirect a parent directory to a child directory. For example, to redirect your home directory (designated by /) to a subfolder named "NewHome", type /NewHome in the Redirect to box, and then click to select this check box. If you do not use this setting, the Web server maps the parent directory to itself.
  • A permanent redirection for this resource.

    If you click to select this check box, the server sends a "301 Permanent Redirect" message to the client. If you do not use this setting, redirect processes are temporary, and the client browser receives a "302 Temporary Redirect" message. Some browsers can use the "301 Permanent Redirect" message as a signal to permanently change a URL, such as a bookmark.
back to the top

Redirect Variables

Use Redirect variables to either pass portions of the original URL with the destination URL or to prevent redirection of a specific file or folder. The following table lists the redirect variables that you can use in the Redirect to box and provides an example of each:

VariableDescriptionExample
$SThe $S variable 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. The server automatically performs this suffix substitution. The $S variable is used only in combination with other variables.If /Scripts is redirected to /NewScripts and the original request is for /Scripts/Program.exe, the suffix is /Program.exe.
$PThe $P variable passes the parameters in the original URL without the question mark that is used to specify the beginning of the query string.If the original URL is /Scripts/MyScript.asp?number=1, the string "number=1" is mapped into the destination URL.
$QThe $Q variable passes the full query string (the question mark and the parameters) from the original URL.If the original URL is /Scripts/MyScript.asp?number=1, the string "?number=1" is mapped into the destination URL.
$VThe $V variable passes the requested URL, without the server name.If the original URL is /Myserver/Scripts/MyScript.asp, the string "/Scripts/MyScript.asp" is mapped into the destination URL.
$0 through $9The variables $0 through $9 pass the portion of the requested URL that matches the indicated wildcard.
!Do not redirect. Use this variable to prevent redirecting a folder or an individual file.


back to the top

Redirect Wildcards

Use redirect wildcards to redirect specific types of files to a particular file at the destination. Use the wildcard character (*) in the Redirect to box to match any number of characters in the original URL.

To use wildcard redirection:
  1. Start Internet Services Manager.

    Alternatively, start the IIS Snap-in in Microsoft Management Console (MMC).
  2. Click to expand * server name, where server name is the name of the server.
  3. Right-click either the Web site or the folder that you want to redirect, and then click Properties.
  4. Click one of the following tabs that is appropriate to your situation:
    • Home Directory
    • Virtual Directory
    • Directory

  5. Under When connecting to this resource, the content should come from, click A redirection to a URL.
  6. In the Redirect to box, type the wildcard redirection values in the following format, where .ext is the extension of the file that you want to redirect, and filename.ext is the destination file name:

    *;*.ext;filename.ext;*.ext;filename.ext

    Make sure that you start the destination URL with an asterisk (*) and a semicolon (;), and you start separate pairs of wildcards 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 line for the Scripts virtual directory:

    *;*.stm;/default.stm;*.htm;/default.htm

  7. Under The client will be sent to, click to select the The exact URL entered above check box.
  8. Click OK.
back to the top

REFERENCES

For more information about redirecting browser requests in IIS, see the "Redirecting Requests to a Directory" or "Redirecting Requests to a Program" topics in the "Web Site Management" section of IIS 5.0 Online Documentation. To view the documentation, start Microsoft Internet Explorer, and then type the following URL in the Address bar: For additional information about browser redirection in IIS, click the article number below to view the article in the Microsoft Knowledge Base:

298408 IIS Generates Courtesy Redirect When Folder Without Trailing Slash Is Requested

back to the top








Modification Type:MinorLast Reviewed:7/15/2004
Keywords:kbhowto kbHOWTOmaster KB313074 kbAudITPro