【问题标题】:What's wrong with IIS7 rewrite ruleIIS7重写规则有什么问题
【发布时间】:2014-05-08 08:55:45
【问题描述】:

我正在尝试从 www 子域到根域的简单重定向。在尝试了许多变化之后,我被困住并希望得到帮助。感觉肯定是一些愚蠢的东西,但看不到它。这是我正在使用的规则。

<rewrite>
  <rules>
    <rule name="Redirect to root" stopProcessing="true">
      <match url=".*"  />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^www.stitchamerica.com$" negate="true" />
      </conditions>
      <action type="Redirect" url="http://stitchamerica.com/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

非常感谢您的输入。

【问题讨论】:

    标签: iis-7 rewrite url-redirection http-redirect no-www


    【解决方案1】:

    这对我有用:

        <rewrite>
          <rules>
            <rule name="Remove WWW" stopProcessing="true">
              <match url="^(.*)$" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
              </conditions>
              <action type="Redirect" url="http://YOURSITE.com/{R:0}" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>
    

    【讨论】:

    • 仅供参考,如果您安装了 URL Rewrite,您可以通过 IIS 访问它。双击并添加规则是编写这些规则的最简单方法。
    • 感谢您的回答,但您的建议也不起作用。我复制了您的代码并替换了我的域名,但没有 Bueno。有什么我想念的吗? IIS7 中的某些设置被覆盖?
    • 这是一个 MVC 应用程序。这会导致问题吗?
    • 有趣,我可以用它重定向到 www.,但不能删除它。我需要对此进行更多研究。
    • 好的,我认为应该可以。我不得不更改匹配 url 和条件模式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多