如何将www重定向到非www?
问题描述:
我正在使用由http://urlrewriter.net/网站提供的URL重写模块。任何人都可以告诉我如何使用他们的模块将www.example.com重定向到example.com(301重定向)。如何将www重定向到非www?
答
如果你只是想重定向www.example.com
:
<if header="HTTP_HOST" match="www.example.com">
<redirect url=".*" to="http://example.com$0" permanent="true" />
</if>
如果你想要的一切,除了重定向example.com
到example.com
:
<unless header="HTTP_HOST" match="example.com">
<redirect url=".*" to="http://example.com$0" permanent="true" />
</unless>
答
我从来没有用过urlrewriter,但它看起来像你使用以下(或类似的东西:
<redirect url="^(.+)$" to="http://example.com/$1" permanent="true" />
在www.example.com网站
答
<redirect url="http://www.example.com/(.+)$" to="http://example.com/$1">
+0
是不是url只是域之后的部分? – configurator 2009-02-28 19:35:32
答
重复的内容重定向没有WWW到www asp.net
<if header="HTTP_HOST" match="^domain.com" url="/default.aspx$">
<redirect to="http://www.domain.com/" />
</if>
<if header="HTTP_HOST" match="^domain.com" url="~/(.+)$">
<redirect to="http://www.domain.com/$1" />
</if>
我测试此代码和它的右
看来你的规则将重定向任何要求,也没有指定的域。我的意思是,如果网站绑定设置为几个域名,他们将被重定向到一个给定的 – abatishchev 2009-02-28 19:25:18
啊,是的,你是对的。我习惯于.htacces,它只影响给定的路径和子路径。 – 2009-02-28 19:38:14