我对IIS不是很了解,但我正在尝试使用URL重写进行重定向。我正在尝试从http://www.cooltoys.com.au/besttoys重定向到http://www.cooltoys.com.au/bestcooltoys
我的Web.config文件中有以下代码,但它不能工作,我很难理解原因。
<rules>
<rule name = "ToysRedirect" StopProcessing="true" />
<match url = "besttoys" />
<action type = "Redirect" url = "http://www.cooltoys.com.au/bestcooltoys" appendQueryString="true" redirectType="Permanent"/>
</rule>
</rules>我认为问题出在“匹配url”部分(模式),所以有人能解释一下如何写这个以便正确地重定向吗?谢谢,科里
发布于 2016-02-24 18:58:17
它将类似于:
<rules>
<rule name = "ToysRedirect" StopProcessing="true" />
<match url = "^(.*)/besttoys$" />
<action type = "Redirect" url = "{R:1}/bestcooltoys" appendQueryString="true" redirectType="Permanent"/>
</rule>
基本上,你需要学习正则表达式。"^(.*)/besttoys$“-意思是我们查找任何以/besttoys结尾的url,然后用/bestcooltoys替换它。字符()定义了一个组,然后我们可以通过{R:1}来引用它-表示第一个定义的组。
https://stackoverflow.com/questions/35600002
复制相似问题