【问题标题】:IIS7 Url Rewrite Add www prefix But Not In IPIIS7 Url Rewrite 添加 www 前缀但不在 IP 中
【发布时间】:2012-12-21 15:57:45
【问题描述】:

我在这里遇到了一个非常有趣的情况,希望你能帮助我。

如果用户输入 domain.com,我会借助 web.config 中的代码将其重定向到 www.domain.com:

  <rules>
    <rule name="Add WWW prefix" >
      <match url="(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.(.+)$" />
      </conditions>
      <action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}"
           appendQueryString="true" redirectType="Permanent" />
    </rule>

这简单而干净,就像一个魅力。但是 domain.com 也有一个像 19.12.121.121 这样的专用 IP。当我尝试使用 IP 连接我的网站时,web.config 会将我重定向到:www.19.12.121.121。

所以问题是,我该如何防止这种情况发生?它会重定向域但IP?

谢谢。

【问题讨论】:

标签: asp.net iis-7 url-rewriting


【解决方案1】:

因为我可以看到您已经在使用 URL 重写:

这是我使用的规则,它适用于我,包括 IP 地址。

<rule name="Redirect to WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" negate="true" pattern="www.(YOUR DESIRED URL).com" />
</conditions>
<action type="Redirect" url="http://www.(YOUR DESIRED URL).com/{R:1}" redirectType="Permanent" />
</rule>

【讨论】:

    猜你喜欢
    • 2011-01-13
    • 2012-04-10
    • 2013-08-01
    • 1970-01-01
    • 2017-08-16
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多