IIS redirect Detailed

Source: Internet
Author: User
Tags http post http redirect
Redirection is a way to ensure that users always receive the pages they need. Redirection is the process of configuring a WEB server to emit a redirect message to a client (for example, HTTP 302) to instruct the client to resubmit the request for a new location. We can redirect users to other files, directories, or sites.

Redirection is useful in the following situations:

-Change the location of the Web site and want to redirect users to the new site.

-The site is under construction, so you want to set some of the site features to be unavailable.

-The content is not placed on the WEB server.

-Changed the name of the virtual directory and wanted the user to be able to access the files in it using the original URL.

(i) Configuring the WEB server to redirect requests to relative targets

If you want to redirect a client to a file, directory, or site, you need to enable redirection and configure the target. This configuration is useful if your site is under construction or if you have changed the identity.

The target you are configuring is a relative target. For example, if the redirection target is configured as Http://www.contoso.com/sales and the incoming request is Http://www.contoso.com/marketing/default.aspx,IIS, the request is redirected to Http://www.contoso.com/sales/default.aspx.

1. Open IIS Manager, and then navigate to the level you want to manage.

2. In the feature view, double-click HTTP redirection.

3. On the HTTP redirect page, select Redirect request to this target. In the appropriate box, type the file name, directory path, or URL to which you want to redirect the user.

4. In the actions pane, click Apply.


(ii) Configure the WEB server to redirect requests to the exact target

If you want to change the default redirection behavior, you can configure the redirection target to be the exact target. When you configure a target as an exact target, all incoming requests are redirected to the exact target rather than the relative target. This configuration is useful if you want to redirect all requests to the same Web page (for example, during a shutdown site for maintenance or site construction).

1. Open IIS Manager, and then navigate to the level you are managing.

2. In the feature view, double-click HTTP redirection.

3. On the HTTP redirect page, under redirect behavior, select Redirect all requests to the exact target (not relative to the target).

4. In the actions pane, click Apply.

(iii) Limit the redirection target to content in the target directory

When redirection is enabled, the requested content is provided by default from the content directory specified as the destination and all of its subdirectories. For example, if you configure a redirection target to be http://www.contoso.com/sales, you might be able to provide content for the request from a directory under/sales. However, you can restrict content to requests only by specifying a content directory that is targeted.

1. Open IIS Manager, and then navigate to the level you want to manage.

2. In the feature view, double-click HTTP redirection.

3. On the HTTP redirect page, under redirect behavior, select redirect requests only to content in this directory (not subdirectories).

4. In the actions pane, click Apply.


(iv) Configure redirect status codes

By selecting the status code, you can specify how the Web browser will issue new requests in different locations. Setting the status code allows you to customize the redirection process.

. Open IIS Manager, and then navigate to the level you want to manage.

2. In the feature view, double-click HTTP redirection.

3. On the HTTP redirect page, under redirect behavior, select one of the following values from the Status code list:

? Standard (302)-instructs the Web client to issue a new request to the location specified in the Location HTTP header.

? "Permanent (301)"-Indicates to the WEB client that a permanent change has occurred to the location of the requested resource.

? Temporary (307)-instructs the Web client to resend the post data in case the Web browser loses data when it makes an HTTP POST request.

4. Click OK.


REDIRECT Reference
Redirecting a client request is a way to ensure that the user gets the correct page, which applies to situations where the site is under construction or has changed identities. You can redirect a client request to a directory on the same WEB server, or redirect to another URL.

REDIRECT Variable
You can use redirection variables to pass the relevant portions of the initial URL to the destination URL. To use these variables, open the properties of a directory in IIS manager. Then select the home directory, virtual directory, or Directory tab, click the Redirect to URL option, and then type a URL in the Redirect to text box to use any of the following variables.

Variable Description Example
The $S transmits the suffix that matches the requested URL. The matching suffix is the part of the initial URL that is reserved after the redirected URL is substituted. If/scripts is redirected to/newscripts and the original request is/scripts/program.exe, then/program.exe is the suffix. The server automatically performs suffix substitution, $S variable can only be used in conjunction with other variables.
$P transfer the parameters in the initial URL. For example, if the original URL is/scripts/myscript.asp?number=1, then the string "Number=1" is mapped to the destination URL.
$Q Pass the question mark (?) and parameters from the initial URL. For example, if the original URL is/scripts/myscript.asp?number=1, then the string "? Number=1" is mapped to the destination URL.
$V the URL for the transfer request, excluding the server name. For example, if the original URL is//myserver/scripts/myscript.asp, then the string "/scripts/myscript.asp" is mapped to the destination URL.
$-$ passes the part of the requested URL that matches the specified wildcard character. For example, if a wildcard character, such as */default.htm, is used in the lowest-level directory name, the part of the directory named "Default.htm" in the URL is passed.
! Not redirected. Use this variable to prevent redirection of subdirectories or individual files in a redirected virtual directory.

REDIRECT Wildcard characters
You can use the redirect wildcard character to match any number of characters in the original URL. Open the property sheet for the directory in IIS Manager, select the home directory, virtual directory or Directory tab, click the Redirect to URL option, and then insert a wildcard character (*) in the Redirect to text box. The destination URL is marked with an asterisk (*) and a semicolon (;) Begins with a semicolon-delimited wildcard character and a target URL.

For example, to redirect all requests for/scripts/filename.stm to a file named Default.stm and redirect all requests to/scripts/filename.htm to the Default.htm file, in the redirect to Type the/scripts virtual directory in the text box:

*; filename.stm;/default.stm; Filename.htm;/default.htm

When using wildcard characters, make sure that the exact URL entered above check box is selected. For the redirect path, type in the URL.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.