djmzfKnm
djmzfKnm

Reputation: 27185

How to redirect www to non-www?

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

Upvotes: 1

Views: 1095

Answers (4)

omid qorbanzadeh
omid qorbanzadeh

Reputation: 11

duplicate content redirect none www to 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>

I test this code and its right

Upvotes: 1

Gumbo
Gumbo

Reputation: 655239

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>

Upvotes: 4

abatishchev
abatishchev

Reputation: 100268

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

Upvotes: 1

Kevin Lacquement
Kevin Lacquement

Reputation: 5117

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.

Upvotes: 0

Related Questions