Iis 如何重定向https://non www-tohttps://www
嗨,我想用https://schema将我们的非www站点重定向到。地点 我使用了下面的代码Iis 如何重定向https://non www-tohttps://www,iis,Iis,嗨,我想用https://schema将我们的非www站点重定向到。地点 我使用了下面的代码 <rule name="Force HTTPS nonwww" enabled="true"> <match url="(.*)" ignoreCase="false" /> <conditions> <add input="{HTTPS}" pattern=
<rule name="Force HTTPS nonwww" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9-]+)$" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" redirectType="Permanent" />
</rule>
当我用http://点击我们的站点时,它工作正常,但当我用https://点击我们的站点时,它抛出404错误
基本上,当我们点击http:或https:到我们的站点时,它应该重定向到
我在IIS 7中测试了上述规则,它在http://和https://上都测试成功,但不知何故,它在https上不起作用://
谢谢你的帮助
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
这表示“不要对传入的https请求执行此操作”。
因为您的两个规则都设置了它,所以您从不重定向https请求。
一般来说,您需要小心,因为您不想进入无限循环重定向=>,所以第二条规则应该保持原样
但是,您可以安全地从以下位置更改第一条规则:
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9-]+)$" />
</conditions>
到
我们能够解决这个问题。由于它抛出无效主机错误,因此无法找到站点名称。因此,我们创建了重定向站点,并使用httpredirect将其重定向回我们的站点 这对我们有用
谢谢大家的帮助。谢谢托兰,我尝试了你的建议,但仍然抛出相同的主机名是无效的错误。我甚至从第二条规则中删除了https输入,但它仍然抛出相同的错误。
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9-]+)$" />
</conditions>