Forum Moderators: phranque
I have a WordPress blog, and I have decided to change my domain name. So, I want any request for the old domain name to 301 redirect to the new domain name.
I've tried various examples I've found in a web search, but haven't found anything that seems to work.
I also want to redirect non-www traffic to the www.newdomain.dom.
So, basically, I am trying to accomplish this:
www.olddomain.dom/* -> www.newdomain.dom/*
olddomain.dom/* -> www.newdomain.dom/*
newdomain.dom/* -> www.newdomain.dom/*
What I keep ending up with is a loop or something that results in a "too many redirects" error in the browser.
I am thinking perhaps one culprit might be this bit of code (which was previously the only code in the .htaccess file):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>
That was code that I found that is supposed to make WordPress more search engine friendly. But, I'm not sure if it's causing a conflict with the redirect codes I've tried, or if I'm just not doing something right.
Thanks.
Code below (add to your WP .htaccess file) could be used to solve...
newdomain.dom/* -> www.newdomain.dom/*
# Redirect if example.com (case-insensitive) to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Correct me if I'm wrong (jdMorgan) but I believe one can use the .htaccess at your new location, with a separate .htaccess 301 redirect to the base url, from your old domain.
As far as location, it's the very same location. I just changed the domain name. Didn't actually move the site to a new location or anything.
Does Technorati not recognize 301 redirects? It looks to me like everything is redirecting properly, but on Technorati, my new domain name shows up as being a new blog, while my old domain name shows up now with a title of Error.
# Redirect if example.com (case-insensitive) to www.example.com
RewriteCond %{HTTP_HOST} old-domain\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Jim