views:

403

answers:

3

I am using URL re-writer module provided by http://urlrewriter.net/ site. Can anyone tell me how can I use there module to redirect www.example.com to example.com (301 redirect)

Thanks

A: 

I've never used urlrewriter, but it looks like you'd use the following (or something similar:

<redirect url="^(.+)$" to="http://example.com/$1" permanent="true" />

on the www.example.com site.

lacqui
It seems that your rule will redirect ANY request, also not domain which is specified. I mean if web site bindings are set to few domains, all of them will be redirected to one given
abatishchev
Ah, yes you're right. I'm used to .htacces, where it only affects the given path and subpaths.
lacqui
+1  A: 
<redirect url="http://www.example.com/(.+)$" to="http://example.com/$1"&gt;
abatishchev
Isn't the url only the part after the domain?
configurator
not working for me :(
Prashant
+4  A: 

If you just want to redirect www.example.com:

<if header="HTTP_HOST" match="www.example.com">
    <redirect url=".*" to="http://example.com$0" permanent="true" />
</if>

And if you want to redirect everything except example.com to example.com:

<unless header="HTTP_HOST" match="example.com">
    <redirect url=".*" to="http://example.com$0" permanent="true" />
</unless>
Gumbo
@Gumbo <if> condition is working for me. <unless> is not working. <if> has one little mistake "http://example.com/$0" it should be "http://example.com$0" else it will redirect you from "www.ex.com/dom/about.aspx" to "ex.com//dom/about.aspx" notice the double slashes. Rest its fine, thanks :)
Prashant
Please edit that slash, for correct answer.
Prashant