URL Rewrite Rule in web.config

本文介绍了IIS中URL重写模块的配置参考,包括如何使用后向引用({R:x} 和 {C:x})以及在条件模式中的应用。强调了在设置规则时,使用括号来定义参数,并通过'{R:1}'获取参数值,多个参数用'&'分隔,同时提醒注意不要重复命名参数。

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

https://stackoverflow.com/questions/16998832/iis-url-rewrite-rn-clarification

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Using_back-references_in_rewrite_rules

And using the input string www.foo.com in the conditions, you will have:

{C:0} - www.foo.com
{C:1} - www.
{C:2} - foo.com

To make it simple:

{R:x} is used as back reference from the rule pattern ().
{C:x} is used as back reference from the condition pattern ()
The 0 reference contains the whole input string
The 1 reference will contain the first part of the string matching the pattern in the first parenthesis (), the 2 reference the second one, etc…up to the reference number 9

Note:

When “Wildcard” pattern syntax is used, the back-references are always created when an asterisk symbol (*) is used in the pattern. No back-references are created when “?” is used in the pattern.

<configuration>
	<system.webServer>
	  <rewrite>
		<rules>
		  <rule name="Angular Routes" stopProcessing="true">
			<match url=".*" />
			<conditions logicalGrouping="MatchAll">
			  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
			  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
			  <add input="{REQUEST_URI}" pattern="^/(test)" negate="true" />
			</conditions>
		    <action type="Rewrite" url="/test/{R:0}" />
		  </rule>
		</rules>
	  </rewrite>
	</system.webServer>
</configuration>

需要IIS安装url rewrite
注意要点
1.参数用“()” 括起来 ,使用 {R:1}来获得参数
2.多个参数中间用 & 分割
3. name切记不能写一样

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值