Posted by: Anthony Drewery | February 19, 2009

Redirecting a WordPress blog using .htaccess

I recently moved my WordPress blog from being self hosted to wordpress.com. The transfer was easy and straightforward. I simply upgraded the original blog to WordPress 2.7 then ran an export followed by an import into the new blog. This uses the WordPress eXtended RSS (WXR) format.

WordPress.com allows me to use my own domain name (blog.drewery.net) but doesn’t let me use a subfolder structure as I did with my original blog (www.drewery.net/blog). This presented a challenge for my existing Google rankings with links to the old location. The solution came from Chris Himsworth, a developer that I work with, in the form of a custom .htaccess file. The file sits in the location of the original blog, parses the URL then redirects to the new location appending part of the original path. By using a 301 permamanet redirect Google then updates the links. The file is below:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ https://blog.drewery.net/$1 [R=301,L]
</IfModule>


Responses

  1. […] OK, as far as changes here, I am going to move my site from the /blog to the main index. Yes, I know I’ll screw up all the pages in Google for a few hours, but thank goodness for redirection (using Apache htaccess.) […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: