你怎么所有URL重定向的组合到https://www.mydomain.ext?
问题描述:
我有一个Windows 2008服务器使用URL重写运行IIS7.5。你怎么所有URL重定向的组合到https://www.mydomain.ext?
我有一个网址,并希望这个网址的所有排列重定向到安全的HTTPS版本以www。因此,例如,我想以下几点:
重定向到:
我已成立了3条重写规则,但不幸的是我不能得到https://mydomain.ext重定向。
下面是我用中间的一个工作不使用重写。不过,我宁愿单一规则来覆盖所有实例。
<!-- Redirect http non www to https www -->
<rule name="Redirect http://mydomain.ext to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.ext" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- Redirect https non www to http www -->
<rule name="Redirect https://mydomain.ext to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="https://mydomain.ext" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- Redirect http to https -->
<rule name="Redirect http to https" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
答
上面的规则的问题是,该协议(HTTPS)是从来没有的主机(HTTP_HOST)的一部分,所以你的规则将不会匹配。你只需要两条规则,但要确保它们是第一条规则并停止处理规则(因为重定向通常应该阻止它们)。所以这应该工作。需要注意的是,其他重要的事情就是用“使用^全字符串匹配和$”,你也能做到这一点确实逆重定向规则的所有,是不是该特定域(见底部):
<!-- Redirect http to https -->
<rule name="Redirect http to https" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
<!-- Redirect http non www to https www -->
<rule name="Redirect mydomain.ext to www" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mydomain.ext$" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
如果你100%确定你只想使用一个域,而且没有其他方法,你可以停止任何变换,然后使用它重定向到规范的变体(而不是上面的第二个规则,在此例中使用否定)
<rule name="Mydomain" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mydomain.ext$" negate="true" />
</conditions>
<action type="Redirect" url="https://www.mydomain.ext/{R:1}" />
</rule>