How To Move Your WordPress Blog The SEO Friendly Way
I recently had the urge to move my 4 year-old WordPress blog from JasonHendricks.com over to a fresh WordPress install on this site, and I wanted to use a newly created directory named /blog/. Why? I didn’t like the layout of the old site at all, plus it makes more sense to blog here than from my own personal domain.
I knew this would be a challenge from a 301 redirect perspective, due to the fact that I decided to go with a completely different permalink structure AND have WordPress installed in its’ own directory instead of the web root like it was on the old site. So I figured I’d share my experiences…
If you need instructions on how to move your entire WordPress install to your new host/domain, check out the following pages depending on your situation:
Move Your WordPress Blog To A New Domain In 10 Steps
How To Move Your WordPress Blog to a New Domain
How To Move From WordPress.com To WordPress.org
The actual moving part was extremely easy, since I didn’t care about the theme, categories, tags, or any extra data from installed plugins remaining intact. In my particular case, I wanted to migrate all posts and comments ONLY, so that’s what I did.
The built-in WordPress import/export functionality didn’t work at all for some reason, so I had to find another way. The next best way to do it (if you’re comfortable working with the database) is below:
Moving Comments and Posts ONLY To A Fresh WordPress Install
- Just to be sure everything goes according to plan and the table structures match, verify that both WordPress installs are the exact same version. Upgrade if not.
- Log into the old WordPress MySQL database via phpMyAdmin (if you have forgotten or don’t know your login details, just open wp-config.php which is in the root folder of your blog…it contains all your db info), then select your database from the available options.
- Export the posts table to a file (also called a sqldump), then save the text file.
- Export the comments table to a file, then save the text file.
- Now log into the new WordPress MySQL database, select the database, then drop the comments and posts tables.
- Go to import and import each sqldump (text files) created from the old WordPress database.
- That’s it!
Great, but you’re not done. You still need a way to permanently redirect all visitors, search engines, and inbound links to the new site without just redirecting everything to the home page.
If you’re keeping the same permalink and directory structure this is very easy, just add this to the .htaccess file on the old site:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^youroldsite.com [NC]
RewriteRule ^(.*)$ http://www.yournewsite.com/$1 [L,R=301]
NOTE: The ‘(*.)$’ says that we’ll take anything that comes after ‘http://www.youroldsite.com‘ or ‘http://youroldsite.com‘ and append it to the end of ‘http://www.yournewsite.com‘ (that’s the ‘$1′ part), and redirect to that URL.
Important Notes About .htaccess Redirection
- Verify that you’re not overwriting an old .htaccess file, sometimes servers place one there for your custom 404 pages, existing applications, etc.
- Always be sure to upload .htaccess files in ascii mode, uploading as binary won’t work.
- .htaccess will not work if you’re on a Windows Server (IIS).
- Since some operating systems don’t allow you to make a file without something before the ‘.’, you may need to save it as htaccess.txt and rename it once you’ve uploaded it.
- Make sure your ftp program will show .htaccess files (FileZilla does and is free).
- Make sure you triple check your changes. Test the server headers to make sure you see a 301 (that means it’s permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.
Unfortunately this was not the case for me. Everything went very smoothly when it came to moving the site itself, but now I need to redirect all old page names to the new URL and permalink structure.
In the past, I had two options here. I could create a very lengthy .htaccess file containing entries that map all old pages to new ones, but this would take forever so that’s out. I could use regular expressions with mod_rewrite in .htaccess to create rules to handle the 301 redirects, but that would be time consuming/complicated as well. What to do?
Luckily there’s a WordPress plugin called Redirection to do this for you. Not only will it save you tons of time, it also automatically prevents headaches for you down the road. Once installed, I was able to create 301 redirects with regular expressions to take care of everything using a simple admin panel:
Let’s run through these quickly, shall we?
Redirections Sorted By Order
- /page/(.*)/ => http://www.tidalwavemedia.com/blog/page/$1 – redirects all requests for paginated URLs to their corresponding paginated URL on the new site, for example ‘http://www.jasonhendricks.com/page/5/‘ to ‘http://www.tidalwavemedia.com/blog/page/5/‘
- /(\d*)/(\d*)/ => http://www.tidalwavemedia.com/blog/$1/$2/ – redirects all requests for date-based URLs such as archives to their corresponding URL on the new site, for example ‘http://www.jasonhendricks.com/2006/06/‘ to ‘http://www.tidalwavemedia.com/blog/2006/06/‘
- /(.*)/(.*)/ => http://www.tidalwavemedia.com/blog/$2.htm – redirects all requests for blog posts using the old permalink structure of /%category%/%postname%/ to their corresponding URL on the new site using the permalink structure of /%postname%.htm (notice the category is stripped from the URL), for example ‘http://www.jasonhendricks.com/seo-advice/how-not-to-be-seen-by-google/‘ to ‘http://www.tidalwavemedia.com/blog/how-not-to-be-seen-by-google.htm‘
- /(.*)/ => http://www.tidalwavemedia.com/blog/$1 – redirects all requests for blog pages to their corresponding URL on the new site, for example ‘http://www.jasonhendricks.com/about/‘ to ‘http://www.tidalwavemedia.com/blog/about/‘
- / => http://www.tidalwavemedia.com/blog/ – redirects all requests for the old parent domain name to the new parent domain, for example ‘http://www.jasonhendricks.com‘ to ‘http://www.tidalwavemedia.com/blog/‘
NOTE: Be sure to test using your old URLs in your browser and verify that the order of redirection is correct. Also note that ‘http://www.youroldsite.com/wp-admin/‘ will no longer work after you’ve configured Redirection as I have. To login to your old site to check redirection/error logs and view stats, use ‘http//www.youroldsite.com/wp-login.php‘.
For more on regular expressions, how to use them with Redirection, and to download the plugin, scroll through the plugin author’s page:
Pretty cool, right (OK…maybe not cool, but you know what I mean)? As if that’s not enough, here are several more features of the Redirection plugin worth noting:
- 404 error monitoring – captures a log of 404 errors and allows you to easily map these to 301 redirects
- Full logs for all redirected URLs
- Automatically add a 301 redirection when a post’s URL changes
- Apache .htaccess is not required – works entirely inside WordPress
- Redirection methods – redirect based upon login status, redirect to random pages, redirect based upon the referrer!
If you find this plugin incredibly useful like I did, be sure to donate to the author and help support free software.
Related Post:



Posted Wednesday, Dec. 23rd 2009 at 4:15 pm by Jason Hendricks


34 comments ↓
Thanks for the post Jason. I experience the same difficulties when migrating old permalink (year/month/day/postname) to the new one (postname). Actually, platinum seo pack automatic redirect works well, except those links ended with trackback. E.g. http://www.fatihsyuhud.com/2005/04/01/most-corrupt-countries-2005/trackback/ cannot automatically redirect to http://www.fatihsyuhud.com/most-corrupt-countries-2005. Can you give me a simple guide what regular expression I should use to redirect those trackback url?
Thanks in advance
Hi Fatih, great question. Below is the regular expression for what you’re trying to accomplish.
Source URL: /(\d*)/(\d*)/(\d*)/(.*)/(.*)/
Target URL: http://www.fatihsyuhud.com/$4/
Hi Jason,
Thanks. Really appreciate. it works.
Two more questions. Hope you don’t mind. How to redirect using regex of these two links (I have many of those)
1. http://www.fatihsyuhud.com/2008/11/18/adobes-hosted-cocomo-service/?referer=sphere_search
to
http://www.fatihsyuhud.com/adobes-hosted-cocomo-service/
2. http://www.fatihsyuhud.com/2008/11/20/prophet-cartoon-by-anonymous-indonesian-blogger-sparks-controversy/?cp=all
to
http://www.fatihsyuhud.com/prophet-cartoon-by-anonymous-indonesian-blogger-sparks-controversy/
Thanks in advance
These redirects would be the exact same as the regular expressions in your first comment, minus the trailing slash, so:
Source URL: /(\d*)/(\d*)/(\d*)/(.*)/(.*)
Target URL: http://www.fatihsyuhud.com/$4/
As I noted in the original post, be sure to test using your old URLs in your browser and verify that the order of redirection is correct.
had been using following permalink
mysite.com/%postid%.html
now i am using this permalink
/%year%/%monthnum%/%postname%/
What regex should I use?
Thanks
Just wanna add that I am using my blog in subdomain
Subdomain.domain.com
Hi, in your first permalink do you mean mysite.com/%postname%.html, not %postid%?
Hi Jason,
I am using post id e.g.
domain.com/2362.html
Just making sure. Try this:
Source URL: /(.*).html
Target URL: /(\d*)/(\d*)/(.*)/
Hi Jason,
Many thanks for your help. Unfortuntely, I am getting 404 errors.
Shob
Hi Shob, after researching this a little more thoroughly, I don’t believe you can correctly setup these redirects using regular expressions.
Unfortunately you will have to create separate 301 redirect entries in your .htaccess file that map old pages to the new ones.
Hi Jason, another question..
How to use regex to redirect non-slash url into the slash one?
Example
http://www.fatihsyuhud.com/tutorial-blog
to
http://www.fatihsyuhud.com/tutorial-blog/
I got some duplicate content issue because of this
Thanks a lot
Hello again Fatih, this one is no problem at all:
Source URL: /(.*)
Target URL: http://www.fatihsyuhud.com/$1/
Jason, I want to do the opposite of what you did. My site is at http://bryansays.com/blog because at first I was going to do something else with the main domain. Well now three years later, I’ve changed my mind and want the blog to reside on the main domain. Any pointers on the best way to do this? Also do you think it will screw up my ranking with google if I make this change?
Hi Bryan, this is no problem at all and very common. Check out the following support page for instructions, specifically the section titled “Moving WordPress Within Your Site”:
http://codex.wordpress.org/Moving_WordPress
Once you have everything moved over, here’s your configuration for the Redirection plugin:
/blog/page/(.*) => http://briansays.com/page/$1
/blog/(\d*)/(\d*) => http://bryansays.com/$1/$2
/blog/(\d*)/(\d*)/(\d*)/(.*) => http://bryansays.com/$1/$2/$3/$4
/blog/(.*)/(.*) => http://bryansays.com/$1/$2
/blog/(.*) => http://bryansays.com/$1
/blog/ => http://bryansays.com/
Be sure to test the old URLs to ensure the order of redirection is correct.
Also, notice that you need to include an extra expression that I didn’t need to because your permalink structure for posts include the date, for example:
http://bryansays.com/blog/2010/02/28/lifestream-digest-for-february-28th
To answer your question about rankings…you might see a temporary decrease in traffic/rankings while Google updates their index with the newly redirected pages, but again this will only be temporary. Since these are 301 (permanent) redirects you will not experience any duplicate content issues.
Hi Jason. You have good post. I really need it. I have a question. How do I redirect the following links using regex:
http://www.mypc-spot.com/2010/03/negeriadscom-solusi-berpromosi-online.html?comments=true
to
http://www.mypc-spot.com/2010/03/negeriadscom-solusi-berpromosi-online.html#comments
Thanks in advance!
Thanks for posting! I really enjoyed the report. I’ve already bookmarked this article for future reference.
Hi, try this and let me know how it goes:
Source URL: /(\d*)/(\d*)/(.*)?comments=true
Target URL: http://www.mypc-spot.com/$1/$2/$3#comments
Great article, very useful for us…thank you
Very good information, you write very well. This information from you helped me tremendously with my blog migration.
Hi Jason,
I catch your post while looking for regex. I know you can answer or confirm, because the first comment in this post seems really similar to my question.
I want to redirect all links in my site:
from: http://example/2010/05/test-this.html
to: http://example.com/test-this.html
or better
to http://exmaple.com/test-this/
can this be the solution
source: /(\d*)/(\d*)/(.*).html
target: example.com/$3/
or what?
thanx in advance,
That’s it exactly Kartal, except you need to make sure you include http in the target, so it would be:
Source URL: /(\d*)/(\d*)/(.*).html
Target URL: http://example.com/$3/
Nice work!
thanks for post, a have one question, is this default theme, or what is her name?
Thanks
Marina
Hi Marina, it’s actually a custom theme.
Jason, thanks for your advice. I forgot to look back to see your response before I went forward with the redirection plugin. If I read your response it would have saved me alot of headache
I basically made a couple sets of redirection entries:
/blog/tag/*
/blog/[year]/*
/blog/[category]/*
I then went through the 404 errors module of the redirection plugin to see if I missed any others. It was definitely a learning experience.
Is there even a way to do this?
Take this:
http://mysite.com/blog/2010/05/12/specific-cat/a-random-post/
To this:
http://mysite.com/specific-cat/a-random-post/
This is my permalink structure: /%year%/%monthnum%/%day%/%category%/%postname%/
Thank you for any insight!!
P.S…Sorry, I only want that url structure for a specific category that I want to appear to be separate from the blog… : )
I believe you can but have no way of testing it myself. Try this and let me know:
Source URL: /blog/(\d*)/(\d*)/(\d*)/specific-cat/(.*)/
Target URL: http://mysite.com/specific-cat/$4/
Poo…throws this error:
“The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.”
The url shown is keeping the /blog/ path as well as the /yyyy/mm/dd/
It’s like it doesn’t like when I try to remove the dates…I have tried a ton of variations and if I use:
http://mysite.com/$1/$2/$3/specific-cat/$4/
I can drop the /blog/ and have it work…but take out 1,2, or 3 and pffftt…
I would even be happy if I could rearrange them i.e.. http://mysite.com/specific-cat/$1/$2/$3/$4/ but it doesn’t like that eithier… : (
Thanks you so much for helping it’s been driving me nuts any ideas are super appreciated!!
Thanks for sharing this.
Dear Jason
You are a life saver. I have spent the last 3 weeks trying to figure out how to redirect my year old site using the redirection plugin and despite a lot of help from a lot of people simply couldn’t figure it out. Your post, images, explanation and responses to comments are possibly the best resource for people who are using the redirect plugin. Thank you very much for putting it out there. Mucho appreciated.
Jawwad
Thanks Jawwad, glad I could help!
Thank you so much for the tips. I was very helpful to me! Cheers.
thnx for this post mate.
I use these tips a lot!
Leave a Comment