使用Intelligencia.UrlRewriter将No-WWW重定向到WWW

时间:2014-01-20 21:43:52

标签: asp.net redirect url-rewriting urlrewriter.net

我有一个ASP.Net网站,我在其中使用模块Intelligencia.UrlRewriter(urlrewriter.net)。我在使用它将无www重定向到www时遇到问题,以避免搜索引擎将这两个网址作为两个不同的网站处理。

我尝试了以下内容:

<redirect url="http://thetotalsite\.it(.+)" to="http://www.thetotalsite.it$1" />

但是它不起作用,或者更好,它“有时”起作用。 例如,如果我尝试达到: http://thetotalsite.it 它重定向到www.thetotalsite.it

相反,如果我有一些跟随主机名的东西,例如: http://thetotalsite.it/a/article-nice-name

它没有重定向。

怎么回事?

(N.d。:我使用以下规则处理文章的url重写:

<rewrite url="/a/(.+)$" to="/articoli/showarticle.aspx?c=$1"/>

提前致谢,

1 个答案:

答案 0 :(得分:0)

显然,我使用另一个stackoverflow问题找到的以下内容解决了:

    <!-- Ensure that all are on the same top domain and sub domain. -->
<unless header="HTTP_HOST" match="www.thetotalsite.it">
    <redirect 
        url="^(.*)$" 
        to="http://www.thetotalsite.it$1" 
        processing="stop" />
</unless>

请注意,如果你有一个过时的UrlRewriter.Net版本,它将无法正常工作。下载并编译最新的资源(2.0.0.9)。