Jam*_*rry 8 redirect iis-7.5 url-rewrite-module
我只想要一个IIS 7.5重写规则将http://www.domain.com/url1重定向到http://www.domain.com/url2(同一个域).这可以通过以下方式实现:
<rule name="Redirect url" enabled="true" stopProcessing="true">
<match url="^url1" />
<action type="Redirect" url="http://www.domain.com/url2"
appendQueryString="false" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
但是,该网站会监听多个域,因此上述内容成为所有域的全局规则.如何将此特定于domain.com?尝试更改匹配URL并添加条件但无法使其工作.谢谢.
Jam*_*rry 10
我让它以这种方式工作:
<rule name="Redirect url1" stopProcessing="true">
<match url="^url1$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(www.)?domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/url2"
appendQueryString="false" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
使用此页面上的答案,我能够为自己调整规则。我还添加了查询参数。想把它贴在这里,以防它对某人有帮助:
<!-- probably requires custom rewrite module, available through web platform installer -->
<rule name="Redirect oldsite.com" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^.*oldsite\.com$" />
</conditions>
<action type="Redirect" url="http://www.newsite.com/page.cfm?userid=123&mode=form"
appendQueryString="false" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
一些解释:
为了澄清一些混淆,这个“url”是域后第一个斜杠之后的部分,而不是整个 url。我将把它放进去,以便它获得任何 URL。
<match url=".*" />
Run Code Online (Sandbox Code Playgroud)
现在,我们将添加一个条件,因为我在这台计算机上有多个网站,因此我想确保此规则仅应用于其中一个。我还使用了通配符而不是“(www.)?” 因为通配符将捕获任何子域。
<conditions>
<add input="{HTTP_HOST}" pattern="^.*oldsite\.com$" />
</conditions>
Run Code Online (Sandbox Code Playgroud)
最后一个注意事项适用于想要放入多个查询字符串参数的人。您需要对它们之间的&符号进行转义,因为如果不这样做,它将无法工作:
<action type="Redirect" url="http://www.newsite.com/page.cfm?userid=123&mode=form"
appendQueryString="false" redirectType="Permanent" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34169 次 |
| 最近记录: |