url将http重定向到非www

url将http重定向到非www

本文介绍了iis url将http重定向到非www https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重定向


-works

www.domain.de to https://domain.de-works


-works

http://www.domain.de to https://domain.de-works


-does not work

http://domain.de to https://domain.de-does not work

rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
      </conditions>
      <action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>


推荐答案

我认为这对您有用,搜索模式有可选的www和重定向使用后向引用C:2,规则有条件只对非https运行。

I think this will work for you, the search pattern has the optional www and redirects using the back reference C:2, the rule has a condition to only run against non https.

这是模式:

"^(www\.)?(.*)$"

其中:

{C:0} - www.domain.de
{C:1} - www.
{C:2} - domain.de

这是完整的规则:

  <rewrite>
    <rules>
      <rule name="SecureRedirect" stopProcessing="true">
        <match url="^(.*)$" />
        <conditions>
          <add input="{HTTPS}" pattern="off" />
          <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
        </conditions>
        <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>

这篇关于iis url将http重定向到非www https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:54