Forum Moderators: phranque

Message Too Old, No Replies

.htaccess and WordPress

Changed my domain name...

         

ccDan

2:54 am on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought this would be easy...

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.

jdMorgan

4:37 am on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> But, I'm not sure if it's causing a conflict with the redirect codes I've tried,

What redirect code have you tried?

Jim

ccDan

6:23 am on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> What redirect code have you tried?

A bunch. But I did get it to work with a 301 redirect in DNS rather than .htaccess. But, I did get the redirect from non-www to www to work in htaccess.

The site is toast at the moment, but I'll post the working code when the site's up again.

venice

6:48 am on Jul 27, 2007 (gmt 0)

10+ Year Member



ccDan, the code you posted is standard wordpress code for permalinks.

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.

ccDan

5:03 pm on Jul 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



venice, your code matches what I ended up using, which appears to be working.

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.

jdMorgan

7:48 pm on Jul 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If all domains resolve to the same server, then you can handle the old domain by adding another line:

# 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]

Not sure about how techno handles redirects. It may be that they spidered while you had the code the loops in place, and their spider got an error or got confused.

Jim

ccDan

5:37 am on Jul 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Technorati doesn't handle redirects. They are URL-based. New URL = New Site.

On the plus side, my Authority rating is now higher on the new blog than it was on the old.