WordPress 301 Redirect – How to Redirect to Preferred Domain

301 Redirect is typically known as a server-side redirect. 301 redirection is used to establish a permanent redirection. The 301 code signifies that a domain or page (s) has permanently moved to a completely new space.

This permanent redirection automatically notifies all your visitors' browsers to correct their impacted bookmarks. It also redirects search engines like Google from a particular domain / URL to the other. There are various scenarios where you might want to perform a 301. Here I am specifically talking about a 301 redirection in WordPress, normally after you have specified a Preferred Domain.

It is recommended (though not essential) that you set your Preferred Domain first, then set your 301 Redirect in WP (WordPress).

How to Set Your Preferred Domain with Google Webmaster Tools

  1. You use a Google Webmaster Tools (it's free).
  2. Log onto your Google Webmaster Tools.
  3. Add 2 Sites – in Google Webmaster Tools: the www- and the non-www version.

For example, let's say your domain name is something witty like "yourdomain.com". In that case, you will be adding the following 2 sites in Google Webmaster Tools:

  • yourdomain.com AND
  • www .yourdomain.com

Remember that at this point, we are only adding the 2 sites. If it makes it easier, just think of them as two slightly different labels of the same domain. After we have added our two sites, we will then set our preferred domain.

(You might need to do site verification as proof that you own that domain. Google will let you know)

After you have added your two sites, then set the ( same ) preferred domain for both of them. ( You can choose either the www- version or the non-www version as the preferred domain). (I tend to choose the www- version as my preferred domain .)

Once you have completed that at Google Webmaster Tools , let's return to your WP Admin.

Setting your 301 Redirect

There are various ways of achieving a 301 server redirect:

  • .htaccess
  • cPanel
  • WordPress (that is for those with a WordPress self-hosted installation)

Note however that if you have a self-hosted WordPress installation, you do not want to do a 301 server redirect using your cPanel. As I recently discovered, it could end up in an endless loop when you try to access your site.

Using WordPress is much easier.

How To Create a 301 Redirect in WordPress

For example: you have installed your WordPress in the root directory (of your hosted domain). We are using the same witty domain as before: "yourdomain.com".

Then you have set your preferred domain to the www version. Next you will want to enforce a server-side 301 redirection so that everything goes to the preferred domain. We will do that in WP (WordPress) itself.

Go to:

WP Admin >> Settings >> General

Change the "WordPress Address (URL)" and the "Site Address (URL)" from "yourdomain.com" to " www .yourdomain.com" ( ie to your preferred domain ).

Save and you are done! Wasn't that fun and easy?