IIS HTTP到HTTPS时,Web应用程序是网站
问题描述:
我有这样的重写规则中:IIS HTTP到HTTPS时,Web应用程序是网站
<rewrite>
<rules>
<rule name="Redirect to http" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" negate="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />
</rule>
</rules>
</rewrite>
我想rediret所有HTTP到HTTPS TRAFIC,但事情是我的web应用程序是不是在根文件夹,所以它是这样的:
http:\\my-site.com\MyWebApp\some-parameters-here
和重定向后它去:
https:\\my-site.com\some-parameters-here
...而不是
https:\\my-site.com\MyWebApp\some-parameters-here
这怎么重定向可以固定而不URL硬作弄那一部分?
答
这对我的作品:
<rule name="HTTP to HTTPS redirect" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^((.+)?my-site\.com)$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
的关键是,替换:{R:1}
。这是允许的,以保持完整的链接没有HTTP_HOST
UPDATE 关于您的评论
您可以使用:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>
肯定。您可以删除该行。这部分我们的配置。我们有几个没有证书的网站。 – SouXin
谢谢,这对我有用。 – ShP