Moving WordPress to a New URL and New Permalink Structure

When I decided to change the permalink structure and move my WordPress blog from raamdev.com to raamdev.com/blog/, 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 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 web root (raamdev.com/), I had to move /blog/index.php to the web root (/index.php) and then edit index.php and change this line,

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

to this,

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

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 web root 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:

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

Now, if someone tries to visit https://raamdev.com/2010/01/28/some-blog-post, the web server will do a 301 redirect to https://raamdev.com/wordpress/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 page rank.

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: https://raamdev.com/2010/01/28/some-blog-post
  2. The .htaccess rule rewrites the URL and redirects: https://raamdev.com/wordpress/blog/2010/01/28/some-blog-post
  3. Dean's Permalink Migration plugin redirects to the new permalink structure: https://raamdev.com/wordpress/blog/some-blog-post

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
  • Site Update: A New Theme « Raam Dev November 29, 2010
  • Raam Dev November 29, 2010