Moving Your WordPress Blog to a New Domain Name or URL

In the past several months I have taken a more active interest in my web presence, namely my websites’ placement in search results for queries of my name. My personal website and blog were previously hosted under two different domain names, and I decided to consolidate the URLs of my personal blog and personal website under one domain name. I wanted to reclaim the previous domain name for another use, and I wanted to accomplish all of this without breaking any existing inbound links to my WordPress blog posts.

With some creative thinking and using mod_rewrite, it is possible to move your blog to a new location, ensure your visitors never miss a beat, and reuse your old domain name. Here is the approach I used to move WordPress to a new domain name without breaking any existing links. For the purposes of this discussion, we will use URL1 and URL2 to stand in for our source and target URLs, respectively. I also assume you are using Apache and that your server/host supports mod_rewrite.

1. The first step is to identify the target domain name, URL2. My hosting company DreamHost has a web-based control panel that makes this part easy, and in my case, I chose to create a new subdomain of my personal website.

2. WordPress provides excellent documentation for how to move the blog itself. Just be careful not to change your permalink structure in the process.

3. You can manipulate the .htaccess file at URL1 to automatically redirect your traffic to URL2. If you have no intentions of reusing this domain, the following code in your URL1 htaccess file will simply redirect all traffic to URL2, preserving the path of the original request:

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

However, if you are like me and you want to reuse URL1 for something else, you can do a bit of pattern matching on the requested paths to redirect only WordPress-specific pages to your new domain. I simply browsed through my own blog and noted that only a handful of paths need to be redirected. Then I created a RewriteRule for each.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$

# If you do not want to redirect your blog's homepage to your new domain name, comment out the next line
RewriteRule ^(.*)$ http://URL2/ [L,R=301]

# Redirect the permalink structure to URL2
# (assuming permalink struct: http://URL1/year/...)
RewriteRule ^2009(.*) http://URL2/2009$1 [L,R=301]
RewriteRule ^2008(.*) http://URL2/2008$1 [L,R=301]
RewriteRule ^2007(.*) http://URL2/2007$1 [L,R=301]
RewriteRule ^2006(.*) http://URL2/2006$1 [L,R=301]
RewriteRule ^2005(.*) http://URL2/2005$1 [L,R=301]
RewriteRule ^2004(.*) http://URL2/2004$1 [L,R=301]
RewriteRule ^2003(.*) http://URL2/2003$1 [L,R=301]
RewriteRule ^2002(.*) http://URL2/2002$1 [L,R=301]
RewriteRule ^2001(.*) http://URL2/2001$1 [L,R=301]

# Redirect these standard locations
RewriteRule ^category(.*) http://URL2/category$1 [L,R=301]
RewriteRule ^author(.*) http://URL2/author$1 [L,R=301]
RewriteRule ^wp-content(.*) http://URL2/wp-content$1 [L,R=301]
RewriteRule ^wp-admin(.*) http://URL2/wp-admin$1 [L,R=301]
RewriteRule ^feed(.*) http://URL2/feed$1 [L,R=301]

# Finally, redirect any Pages you may have
RewriteRule ^about(.*) http://URL2/about$1 [L,R=301]

The only catch here is that if you want to reuse URL1, you cannot duplicate any of the paths that you are redirecting because your visitors will never see that content. If you use a different permalink structure, simply adjust the regular expressions in each RewriteRule to match.

Hopefully this helps with your next WordPress move. With the magic of mod_rewrite and some creative htaccess entries, your visitors will arrive at your blog’s new location without incident and never the wiser.


Leave a Reply

Your email address will not be published. Required fields are marked *