Having just done this to move from apartmentonesix.com to yourcodegarage.com, I figured it would be fitting to write a quick post about how to handle this sort of redirection.
It’s important to know the goal – in this case, we want to move a site from one url to another. For example, from
However, we’re actually moving all the content and everything over – so we want to redirect the individual urls, like this:
That way any bookmarks or incoming links pointing at the old site will redirect properly at the new one.
First things first, you need to duplicate your WordPress installation from the old site onto the new one. Here’s the drive by version of how to do that:
We’ll be back to thsi site in a bit to implement the redirect, but for now, we’ll move to the new site.
All we’ve got left to do is redirect your old site to the new one. Unfortunately, this is often the scariest and most difficult part of the entire process. On the bright side, you should be able to just paste this code in and call it done.
To accomplish our redirect, we’re goign to modify the .htaccess file of our old site. .htaccess is a file that you can use to give your server special instructions on how to handle certain requests to your site. Because it starts with a dot, it’s often hidden by FTP clients – so you may have to do some tinkering to have it visible and editable to you.
Here’s the code we’re going to use:
RewriteEngine on RewriteRule ^(.*)$ http://yourcodegarage.com/blog/$1 [R=301,L]
Obviously, you’re going to want to replace “yourcodegarage.com/blog” with your own url. Just put that at the top of your .htaccess file, and you should be all set. Here’s the gist of what’s happening:
Here, we’re just telling the .htaccess file to make sure the rewrite engine that your webserver uses is running, and able to handle the request.
We start the line with the word “RewriteRule”, because that’s what we’re defining – a rule for the server to use in rewriting the url and sending the user to where we want them.
I’m not going to get into the nitty gritty of the regular expression being used here, but what you need to know is: This section says “Match the entire url (after the domain name), and store the whole thing for me to use later in this line.”
At this point, we give the url we’d like to send the user to. In my case, I needed to send the user to yourcodegarage.com/blog, because that’s where the blog is now located. The $1 after that is telling the server to append whatever we found before to the end of this. So, if the old url was
then “my-post/comments” would be grabbed, and appended to the end of “http://yourcodegarage.com/blog”, ensuring that the user gets sent where he needs to go.
We finish up with this:
All we’re saying here is use a 301 redirect (permanent), and don’t listen to any redirect rules after this one.
And with that, we’re all set! Make sure you use Google Webmaster Tools to notify google of the change, and get to work blogging at your new url!