【问题标题】:ignore IP while redirecting to www in web.config在 web.config 中重定向到 www 时忽略 IP
【发布时间】:2016-02-24 02:32:09
【问题描述】:

出于SEO 的目的,我的web.config 文件中有这部分代码。它允许我将所有 URL 重定向到我网站 URL 的 www 格式(例如,它将 abc.com 重定向到 www.abc.com

<rule name="Redirect to www" stopProcessing="true" >
  <match url="(.*)"/>
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www\." negate="true"/>
  </conditions>
  <action type="Redirect" url="http://www.{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false"/>
</rule>

现在我的问题是它还将我网站的 IP 重定向到 www 格式(我的意思是将 123.123.123.123 重定向到 www.123.123.123.123

如何从该操作中排除我网站的 IP?提前谢谢。

【问题讨论】:

  • 为什么不直接说 - &lt;action type="Redirect" url="http://www.foo.com" ....

标签: asp.net redirect web-config seo url-redirection


【解决方案1】:

只需添加另一个否定规则来测试 REMOTE_ADDR 到条件。

<rule name="Redirect to www" stopProcessing="true" >
  <match url="(.*)"/>
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www\." negate="true"/>
    <add input="{REMOTE_ADDR}" pattern="123\.123\.123\.123" negate="true" />
  </conditions>
 <action type="Redirect" url="http://www.{HTTP_HOST}{HTTP_URL}" redirectType="Permanent" appendQueryString="false"/>
</rule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多