繁体   English   中英

网址重写-Web.config-HTTPS和www

[英]Url Rewrite - Web.config - HTTPS and www

我需要能够重定向到HTTPS(当前正在工作)和www(如果它不在URL中)。

如果网址具备www ,然后正常工作。 但是,当URL DOES具有www ,它将重定向并添加其他www ,例如https://www.www.domain.com

请注意,我不想对域进行硬编码,而是想使用HTTPHOST或类似的东西。

当前的重写规则:

    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
    <rule name="WWW Rewrite" enabled="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
      </conditions>
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
    </rule>

最终得到此正则表达式- ^((?!www).)*[a-zA-Z0-9]+$

我还必须进入IIS,并将“与模式不匹配”​​更改为“与模式匹配”

    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
    <rule name="WWW Rewrite" enabled="true" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^((?!www).)*[a-zA-Z0-9]+$" />
      </conditions>
      <action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
    </rule>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM