【问题标题】:Site getting redirect to www.www.sitename.com网站重定向到 www.www.sitename.com
【发布时间】:2016-07-14 05:42:06
【问题描述】:

我的网站被重定向到 www.www.sitename.com 时遇到这个问题。

我在 web.config 中编写了这段代码,在我的其他网站上运行良好。

<system.webServer>
    <rewrite>
      <rules>

        <clear />
        <rule name="Redirect to WWW" 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>

      </rules>
    </rewrite>
  </system.webServer>

这是 100% 其他网站的工作代码,但在此网站上存在 www.www.sitename.com 的问题 srilanka-tours.co

【问题讨论】:

  • 顺便说一句,我刚刚访问了您的 srilanka-tours.co 网站并被 not 重定向到双 www 网址。玩过重写后,浏览器中可能存在一些缓存问题?
  • 我已经更新了您发送给我的代码,它工作正常。但仍然混淆为什么它不能与通用代码一起使用。
  • 感谢@UweKeim,我会研究这篇文章。

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


【解决方案1】:

不如让它不那么通用,更专注于您的实际主机名?

例如:

<rule name="Redirect to WWW">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^www\.srilanka-tours\.co$" negate="true" />
        </conditions>
        <action type="Redirect" 
                url="http://www.srilanka-tours.co/{R:1}" 
                redirectType="Permanent" />
</rule>

(这是现实世界重写规则的摘录)。

上述规则类似于您在 IIS 管理器的“向导”中使用“规范域名”来创建重写规则时得到的规则。 See the article on Scott Guthrie's blog.

【讨论】:

  • (R:1) 和 (R:0) 有什么区别?您在代码中使用了 (R:1)
  • 感谢您的帮助。更新导览后网站运行良好。
猜你喜欢
  • 1970-01-01
  • 2019-01-29
  • 1970-01-01
  • 1970-01-01
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多