301 网址转向带参数

本文详细介绍了如何使用IIS进行URL重定向,并提供了具体的配置步骤和示例。包括如何实现从一个域名到另一个域名的301永久重定向,以及如何利用变量和通配符来灵活配置重定向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

比如要从aaa.com/a.asp?a=a&b=b的任何url转向www.aaa.com/a.asp?a=a&b=b,考虑到搜索引擎,所以客户要求301转向。

1 在IIS里新建一个网站指向要转向的网站目录,即两个网站指向同一个目录。第一个网站的host header是www.aaa.com,但不要配置aaa.com,否则第2个网站的aaa.com就不会运行了,因为他们争夺80端口,第2个host header是aaa.com

2 在第2个网站aaa.com配置(home directory->redirect to....)写上网址:http://www.aaa.com$S$Q,这样网页名和参数就都过去了,Warn:必须选中下边的第1和3的checkbox,否则不起作用。

 

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.

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 HttpRedirect metabase 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.

 
VariableDescriptionExample

$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 toDestinationN 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/Scripts

is configured with the following redirection string:

*; /Scripts/*_in.asp; /NewScripts/$0.dll; /Scripts/*_out.asp; http://contoso/NewScripts/$0.dll

A new request for the following URLs:

http://fabrikam/Scripts/data_in.asp

http://fabrikam/Scripts/data_out.asp

Would 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.

 
FlagUser Interface Check BoxDescription

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 resourcecheck box"

Indicates that this redirection is temporary for this resource.

Related Information

For information about configuring URL redirection by using IIS Manager, see Redirecting Requests to Files, Directories, or Programs.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值