I recently moved my blog over to a new domain and a new WordPress installation. I wanted to move my blog to it’s own FQDN (previously it was in a subdirectory under another website). Also, when I was setting up my old blog, I wanted to to be integrated into the other website.
The site was structured with Smarty PHP templates, and I had wanted the blog to look like the rest of the site, and just show up as a menu item. I did all sorts of horrible things to the theme in WordPress to make it part of my Smarty-based site. As such, I was too scared to ever update WordPress, for fear of completely breaking stuff. Given some of the security issues that WordPress has seen, this was not a good thing.
When I began thinking about moving my blog to a new FQDN, I realized that I also wanted to just start fresh with a new layout, and a simpler setup. I wanted to move all of my content though, and also not break anything that was linked to my old site (or lose any of the few people who might be subscribed to the RSS feed). The new site is hosted on the same server, but it’s completely separate from the original. To keep things easy, I’m using the same path structure on the new site as I did on the old one. If an old post was at http://www.getsimpliciti.com/blog/2012/12/a-blog-post, it is now at http://blog.garraux.net/2012/12/a-blog-post.
There were basically three things I had to do in order to move everything over.
Export the Text Content
WordPress has a built in feature to export and import content. This worked pretty well for me – but this doesn’t export any images or other external content. Also, if you’re moving to a different address, exporting and importing will not update links within your content to the new address.
Thankfully, the export is just a simple XML file. So, it’s pretty easy to do a search and replace to modify them to point to your new address. I did this to change any links pointing to http://www.getsimpliciti.com/blog/* to http://blog.garraux.net/
Since the export / import just works with the text content from the database, any images or other files that have been uploaded won’t be moved over. All of my uploaded content was in the wp-content/uploads directory. Since I’m using the same directory structure, and I updated all of the links in the text content, I just had to copy the wp-content/uploads directory from my old install to the new install.
There were two aspects that I was concerned about regarding handling HTTP requests for content. First, I wanted users browsing to a specific post to be HTTP redirected to the corresponding post on my new site.
Second, I was concerned about people who might be using the RSS feed. I’m not familiar enough with what RSS clients are out there, and how they react to HTTP redirects. So, I wanted to transparently rewrite these requests to the RSS feed URL on my new site. This took a little more time to figure out than I was initially anticipating.
I ended up with the Apache redirect configuration below, in the <Directory> configuration for the old site. The RewriteRule statements are rewriting the requests for the RSS feed to the new site. The RedirectMatch statement below them sends an HTTP redirect to the new site for any request that’s not going to the RSS feeds. It handles deep links, so links to a particular address under /blog on the old site are redirected to that same URL (without the initial /blog) on the new site.
RewriteEngine on RewriteRule ^blog/feed$ http://blog.garraux.net/feed/ [L,P] RewriteRule ^blog/feed/$ http://blog.garraux.net/feed/ [L,P] RewriteRule ^blog/comments/feed$ http://blog.garraux.net/comments/feed/ [L,P] RedirectMatch ^/blog/(?!(feed|comments/feed))(.*) http://blog.garraux.net/$2