繁体   English   中英

在IIS7上重写无法与“ www”一起正常使用

[英]Rewrite on IIS7 not working correctly with “www”

我的重定向规则有问题。 我希望我的页面具有“ www”前缀。 它可以在某些页面上运行,而在另一些页面上则什么也不做。 这是我的规则:

    <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="http://www.{HTTP_HOST}/{R:0}"
        appendQueryString="true" redirectType="Permanent" />
    </rule>

任何帮助将不胜感激!

您可以试试这个^(www。)?([。a-zA-Z0-9] +)$

如果该页面当前没有“ www”,则将与之匹配。 并且应该匹配(无论是否匹配)。

您将需要对此操作进行编辑以选择第二组<action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />

这是您的规则,您只需要检查主机是否与预期的主机不匹配,然后重定向到正确的URL。

  <rules>
    <rule name="Canonical Host Name" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.domain\.com$" />
      </conditions>
      <action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>

暂无
暂无

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

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