301 redirect www. to non-www?

Sharksfan

New member
May 28, 2009
1,088
22
0
WI
(kind of a repost - to the right forum this time)

I have a Wordpress installation that uses the hxxp://mydomain.com as the URL.

hxxp://www.mydomain.com will of course re-direct via Wordpress' built in features but I'd rather do it via a 301 redirect in order to fix some backlinking issues. My best backlinks are via the non-www domains.

I can find plenty of examples of 301 re-directing from non-www to the www, like this in a .htaccess file:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) [URL]http://www.mydomain.com/$1[/URL] [R=301,L]

Is it safe to say the appropriate way to do it to go www > non-www would be this?

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) [URL]http://mydomain.com/$1[/URL] [R=301,L]
 


I don't think what you have will work, it'll either loop or not work. You need:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[URL="http://www.domain%5C.com/"]www.domain.com[/URL]
RewriteRule (.*) [URL="http://www.wickedfire.com/redirect.php?url=http%3A%2F%2Fmydomain.com%2F%241"]http://mydomain.com/$1[/URL] [R=301,L]
The www on the first one. Also, on the site that I have this working I don't have the '.' escaped, so I don't think you need that.