我正在尝试编写IIS7 URL重写规则,它做了两件事:
在这两种情况下,我都想重定向到https://my.domain.com(替换真实域名)
我对http到https规则没有问题。此外,http://www.my.domain.com到https://my.domain.com的情况也有效。但是,我无法开始工作的一个案例是原始请求是https://www.my.domain.com
这就是我现在所拥有的:
<rule name="r2" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{SERVER_PORT}" pattern="443" negate="false" matchType="Pattern" />
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" matchType="Pattern" />
</conditions>
<action type="Redirect" url="https://my.domain.com" />
</rule>
<rule name="r1" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{SERVER_PORT}" pattern="443" negate="true" matchType="Pattern" />
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" matchType="Pattern" />
</conditions>
<action type="Redirect" url="https://my.domain.com" />
</rule>
了解我需要更改哪些内容才能让https://www.my.domain.com重定向到https://my.domain.com?
答案 0 :(得分:0)
这可能适合你
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_HOST}" pattern="https://mydomain.com$"/>
</conditions>
<action type="Redirect" url="https://www.mydomain.com/{R:1}" redirectType="Permanent"/>
</rule>
答案 1 :(得分:0)
试试这对我有用
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="permalink">
<match url="article/(\D+)(\/)*$" />
<action type="Rewrite" url="http://mywebsite.com/article.aspx?id={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>