Creating a 301 redirect for WordPress blog

301 redirect responseThere are zillions of how-to articles on creating 301 redirects. However, this brief article will focus on creating a redirect for non-WWW queries of your domain name to WWW, by editing the .htaccess on a WordPress blog. You may ask, why should I do this? Because, all search engines treat www.yoursite.com and http://yoursite.com as two different sites. Also, one of these two will be penalized by the search engines for duplicate content. It might sound silly and stupid, but it’s 100% true.

Just to quote a piece from Google Webmaster Central

People access your site through several different URLs. If, for example, your home page can be reached in multiple ways – for instance, http://example.com/home, http://home.example.com, or http://www.example.com – it’s a good idea to pick one of those URLs as your preferred (canonical) destination, and use 301 redirects to send traffic from the other URLs to your preferred URL.

Here are the steps:

  1. This .htaccess is super sensitive to syntax errors, with the potential of rendering a site inactive. Before you edit, make a backup of the file
  2. Open .htaccess, and copy the following code just after the # -FrontPage-

Note: replace yoursite with your domain name

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]

That is it! Upload the .htaccess file back to the root folder, or where ever it was, via FTP. Check if your site redirects properly.

Like I said, though there were a lot of articles on 301 redirects, I was clueless with the WordPress .htaccess file. Hope this little tip helps you in getting better with search engines.

Do share your thoughts on this.