on Technology

Moving WordPress to a New URL and New Permalink Structure

When I decided to change the permalink structure and move my WordPress blog from blog.raamdev.com to raamdev.com, I knew it was going to be a delicate process. I have over a thousand posts, more than three hundred of which have been indexed by Google. A huge portion of my traffic comes from Google, so my biggest concern was that the old URLs redirect to the new location.

Step 1: Disable plugins

It's a good idea to disable your plugins before making these changes. At the very least, if you have a caching plugin installed (such as WP Super Cache), delete the cache and then disable that plugin.

Step 2: Change the blog URL

First, I had to change the WordPress blog URL from blog.raamdev.com to raamdev.com/blog/. This is simply a matter of updating the "WordPress address" and "Blog address" options from within the WordPress Administration panel (Settings -> General).

Second, I wanted the final URL to be raamdev.com/, instead of raamdev.com/blog/. To do this, I first changed the "Blog address" to raamdev.com/. Now to get WordPress working on the webroot (raamdev.com/), I had to move /blog/index.php to the webroot (/index.php) and then edit index.php and change this line,

[sourcecode]
require('./wp-blog-header.php');
[/sourcecode]

to this,

[sourcecode]
require('./blog/wp-blog-header.php');
[/sourcecode]

Now, when index.php is loaded, it knows to look for all the WordPress files in /blog/ and since WordPress has been configured to use raamdev.com/ as the "Blog address", it will automatically handle everything else.

Step 3: Redirect old URLs to the new URL

The blog. sub-domain maps to a directory in the webroot called /blog/. If someone visits a link to a page that includes the sub-domain, the web server needs to tell the browser the new location. To do this, I needed to recreate the /blog/ directory and add the following to an .htaccess file:

[sourcecode]
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.raamdev.com$ [NC]
RewriteRule ^(.*)$ http://raamdev.com/blog/$1 [R=301,L]
[/sourcecode]

Now, if someone tries to visit http://blog.raamdev.com/2010/01/28/some-blog-post, the web server will do a 301 redirect to http://raamdev.com/blog/2010/01/28/some-blog-post.

What's a 301 redirect? Well, when you move a web page from one location to another, you can specify the type of redirection. A 301 redirect means the web page has been moved permanently. This is useful for keeping indexes updated. For example, if someone searches Google and finds an old link, Google will detect the 301 redirect and update its index with the new URL, thereby keeping your URL's pagerank.

Step 4: Change Permalink structure

To change the permalink structure, I used the awesome Permalink Migration plugin by Dean Lee. With this plugin, I just specify the old permalink structure (in my case, this was /%year%/%monthnum%/%postname%/) and then change the permalink structure in WordPress (Settings -> Permalinks) to the new format (I'm using /%postname%/).

Now whenever someone visits a URL using the old permalink structure, Dean's plugin sends a 301 redirect to the new URL.

Summary

With the .htaccess rewrite rule and Dean's Permalink Migration plugin, we now have a double 301 redirect to make sure the old URLs redirect to the new ones:

  1. Someone searches Google and finds this link to my site: http://blog.raamdev.com/2010/01/28/some-blog-post
  2. The .htaccess rule rewrites the URL and redirects: http://raamdev.com/blog/2010/01/28/some-blog-post
  3. Dean's Permalink Migration plugin redirects to the new permalink structure: http://raamdev.com/blog/some-blog-post

Leave a Reply for Raam Cancel Reply

Write a Comment

Comment

    • Hi Tom,

      Try changing this line:
      RewriteCond %{HTTP_HOST} ^tomcatblog.info$

      to this:
      RewriteCond %{HTTP_HOST} ^tomcatblog.info/$

      Hope this helps!

Webmentions

  • Colleen Greene November 29, 2010

    Moving WordPress to a New URL and New Permalink Structure – Solid State Raam http://ff.im/-wDLYH

  • Site Update: A New Theme « Raam Dev November 29, 2010

    […] If you’re interested in the technical details of how all this was done, check out my latest post on Solid State Raam. […]

  • Raam Dev November 29, 2010

    New on solidstateraam.com: Moving WordPress to a New URL and New Permalink Structure http://bit.ly/9nYqTA