How to change your wordpress directory URL and redirect the traffic (.htaccess, 301 redirect, permalinks)

I’ve been planning to move my wordpress blog (this one actually) from it’s old URL- http://turcanu.net/blog , to a subdomain within the same domain name – http://sergiu.turcanu.net for a long time now, and finally I did the transfer today which went all smooth and fine, although I thought it would require some additional hacks inside the .htaccess file. The thing is, I also wanted to get rid of my old long permalinks that included the year, month and date along with the post title, and get them to display just the post title. So, what used to look like this: http://turcanu.net/blog/2006/11/05/on-the-train-to-lhasa/ now is changed and shorten to: http://sergiu.turcanu.net/on-the-train-to-lhasa/

I’ll try and do a quick tutorial on how to apply this changes and still retain the traffic from the old URL’s through 301 redirects applied in the .htaccess file. In case you’re not aware – 301 redirects in .htaccess are also considered the best way to tell search engines that your page moved permanently, which is good for your SEO. This tutorial is also good for when switching to a new domain name.

  1. Login to your existing wordpress admin panel and change the WordPress address (URL) and Blog address (URL) from the General Settings with your new URL address for your blog. Beware that when you click on saving these new settings you’ll modify the paths from inside the database and your wordpress blog will not be operational anymore (you will not be able to login to the admin panel either), so don’t be surprised to see the 404 Error Page. If for any reason you would want to change those back – you’ll need to do this from your phpMyAdmin panel.
  2. Back up you existing wordpress database if you intend to switch servers (make sure you tick “DROP TABLE” when exporting the database via phpMyAdmin) and copy the entire wordpress directory in use to your computer. In fact I would recommend you do an extra database copy before applying changes in step one, just in case.
  3. Move/Copy your wordpress directory files (all of them) to your new location. Install the wordpress database to the new server if needed (when moving inside the same domain name that will not be the case). You don’t need to apply any changes to the wp-config.php unless your new server settings require setting a different db host from the traditional ‘localhost’, which is very unlikely; or if you created a different set of database connection details.
  4. Try out the new URL and login to your admin panel from there. Change the permalinks to a new set if you want. I recommend using the custom structure to suit your needs, I used a simple /%postname%/.
  5. Place a .htaccess file to your old wordpress directory with the following content:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://www.your-domain.com/$1 [R=301,L]

    (replace www.your-domain.com with your own wordpress URL in use). This will 301 redirect all the old paths from your previous wordpress location to the new one (e.g.: from http://turcanu.net/blog/ to http://sergiu.turcanu.net/, from http://turcanu.net/blog/2007/04/29/my-last-cigarette/ to http://sergiu.turcanu.net/2007/04/29/my-last-cigarette/ and so on). You may swipe the content of your old wordpress directory and leave just the .htaccess file.
  6. Now, if you applied some changes to the permalinks as well, you will need a special and easy to use plugin for another set of redirections – Permalink Redirect WordPress Plugin. After downloading, installing and activating it go to Settings>Permalink Redirect and specify your “Old Permalink Structures” (in my case it was: /%year%/%monthnum%/%day%/%postname%/)
  7. And that’s about it! Test it! (you might find the old XML sitemap handy for that purpose). One quick note though: if you were using a different path for your uploads in the “Miscellaneous Settings” – change them to what you want to use.

Sergiu

Related Posts

Puţină critică pentru organizatorii AdWeb 2012

Puţină critică pentru organizatorii AdWeb 2012

Bannere GRATIS pentru bloggerii moldoveni!

Bannere GRATIS pentru bloggerii moldoveni!

Am lansat moldo.net – pagina de start pentru internetul moldovenesc!

Am lansat moldo.net – pagina de start pentru internetul moldovenesc!

Choosing a web hosting provider? May I recommend?

Choosing a web hosting provider? May I recommend?

3 Comments

Leave a Reply

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