Easy Wordpress .htaccess 301 Redirect

October 17, 2008 by BlogCrafted Staff · Blogging with Wordpress, Tutorial  

Recently, I moved a Wordpress blog from one domain to another. Most of the time, I work with blogging platform transfers or possibly moving the domain from one host to another.

In this case, I needed to direct traffic arriving at any page on the old domain to the same page on the new domain. I knew that I wanted to do a 301 redirect, but I hadn’t anticipated how simple the whole thing would be. I had anticipated a long list of redirects.

But it turns out that if you migrate a Wordpress blog from one domain to another domain, then all you need to do is make a small change to your .htaccess file at the old domain.

If there isn’t anything about the “RewriteEngine” in the .htaccess file, then add the following:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Replace www.newdomain.com with whatever your new domain is. Use “www” or not as you see fit.

However it’s quite likely that in the section following:

# BEGIN WordPress

you’ll find the first two lines:

Options +FollowSymLinks
RewriteEngine on

Directly after those, before any other rewrite commands, place:

RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

again replacing www.newdomain.com with the blog’s new domain.

This works on Linux servers which have Apache Mod-Rewrite enabled. That sounds very technical, but it’s also what’s offered by a large number of hosting companies. If you don’t know whether or not you have that, give the redirect a shot. You can always contact your hosting company if it doesn’t work and ask for their suggestions.

It takes about 20 seconds to do. And this works whether or not you still have Wordpress installed on the old domain. I deleted the entire Wordpress installation and just left the redirect up. Every link goes through to the new site.

A 301 redirect isn’t as good as a direct link, but in terms of traffic and even SEO it’s a best choice. Gives you time to find out who’s linking to your old site and ask them to change while making people follow those old links to the right place anyway.

If this is still confusing or you don’t feel comfortable doing it yourself, just contact me for a very reasonable quote!

{ 12 comments }

1 Anand Srinivasan March 5, 2010 at 4:43 am

Hi Ms. Crafty

That sounds way simple..But let me confirm..Doing this will redirect a visitor coming to http://www.olddomain.com/2010/03/page to http://www.newdomain.com/2010/03/page right?

Also, should I continue to retain both my domains or can I discard my old domain after sometime?

Thanks a lot for this post..
.-= Anand Srinivasan´s last blog ..Social Networks Access Via Mobile Browsers =-.

2 BlogCrafted April 4, 2010 at 9:42 pm

Yes, that’s what will happen. As long as the site is now at the new location, it’ll work smoothly. Otherwise they’ll get redirected to that page but there won’t be anything there. You’ll need to keep the old domain as long as you think there’s incoming traffic. If it didn’t have many links, then after a year when the search engines have switched over you’ll probably be fine. But if a lot of people had linked to it, then when you discard it you lose all that traffic (unless you get the people to change their links).

3 Sweta May 31, 2010 at 7:04 am

Hi,
I am a software developer and use wordpress extensively to build various websites for our company clients.
The redirect process explained here will redirect everything but is there a way to redirect only one page? Something like redirecting http://yoursite.com/home/ to http://yoursite.com/ ?

4 BlogCrafted May 31, 2010 at 9:07 am

Hi Sweta, try:

RedirectMatch 301 ^/home/$ http://yoursite.com/

5 Gagan August 19, 2010 at 10:14 pm

hey mate!
Nice post but can we use .htaccess to redirect traffic between sub-domain and root on the same server? I am having this problem.
What I have done is—I have moved my wordpress blog on the root from a subdomain and deleted the sub-domain….now google is not optimizing my website as it thinks that I have copied the content and using it at another place and hence it has penalized me!…I have lost the whole SEO. Please help urgently…i’ll re-install sub-domain and can quickly use .httaccess redirects, if possible…please help?

6 Parneix September 22, 2010 at 8:02 pm

Hi,

I’m moving a Wordpress blog from mydomain.net/blog to mydomain.net (so basically just moving it to the root). I’ve tried many command line for the .htaccess file, but they all failed to redirect to the root.

1) I didn’t have any .htaccess file before. I created one just for this. Is it the only command line I should use or should there be other stuff in there?
2) The .htaccess file should be place in mydomain.net or mydomain.net/blog ?
3) Just for the record, I didn’t assign a www to mydomain.net. I choose the option “leave it alone”. So both are supposed to work.

Thanks for the tips by the way.

Prnx

7 yousaf November 17, 2010 at 2:57 am

thanks for the article,
But I have some questions, can you pls answer theme?
1. Will I loose my google pagerank using this redirection?
2. Will the old blog be opened and then redirect to the new blog or is it transparent?
3. Can i delete all files and database except .htaccess file?
Please reply soon because i want to migrate.

8 Chris June 7, 2011 at 4:58 am

This was very useful. I will add, changing all the pictures / file paths from the old domain trough phpmyadmin, details here: http://lorelle.wordpress.com/2005/12/01/search-and-replace-in-wordpress-mysql-database/ (it will replace the domain name). And don’t forget to do some tweaks from webmaster tools to tell google of this move.

9 Michael June 21, 2011 at 2:49 am

Hello,
I’m missing something… I’ve used your code in the .htaccess of the original site, and it does redirect. Problem is that its redirecting to index.html, and my newsite WP uses index.php…
so i get a 404 error, page not found

HELP. I’ve been searching everywhere, and i know i’m just missing something silly.

thank

10 Chris June 21, 2011 at 3:31 am

Michael, try to add this code in htaccess:

Redirect 301 /index.html http://yournewwebsite.com/index.php

Test then with some tools if the 301 redirect is fine cause I’m not 100% sure.

11 Michael June 27, 2011 at 8:16 am

Hello,

Thanks for all the help…
In the end, and after lots of research, it wasn’t the redirect that was the problem. It was the receiving site’s htaccess that needed editing.

I added the following code just before the #BEGIN Wordpress

DirectoryIndex index.php index.html
Redirect permanent /index.html
http://www.site name.com/

After that the redirect was seamless. I just needed the redirect for a .html to pick up a .php file, and this did the trick.

Thanks again, and hope this helps others

12 WordPress Mover August 15, 2011 at 9:22 pm

If you have access to cPanel, look for the “Redirect” menu option for a simple, GUI driven way to accomplish the same thing.

Comments on this entry are closed.