WordPress SEO Tutorial updated February 2014

A permanent 301 redirect informs search engines and browsers (Firefox, Google Chrome, Microsoft Internet Explorer etc…) a page has permanently moved to a new location. A visitor to a website visiting via a link that’s been 301 redirected will click a link with one URL, but load another URL.

For example I moved some articles from another site to here, if a visitor found a link to http://www.stallion-theme.com/wordpress-seo-tutorial-duplicate-content-and-canonical-urls (old location) it would load https://stallion-theme.co.uk/wordpress-seo-tutorial-duplicate-content-and-canonical-urls/ (new location) in a browser since there’s a 301 redirect on the old site (added to the .htaccess file) to here.

WordPress SEO 301 Redirects
Search engines like Google will pass any SEO benefit (PageRank for example) and traffic from the old URL to the new URL.

So when Googlebot (Google search engine spider) has spidered the old URL it will stop indexing the old URL and only index the new one (give it a few weeks, don’t expect the change to be overnight): this means current Google SERPs for the old page will be associated with the new page.

SEO note: there’s a small dampening factor on the PageRank passed via 301 redirects, based on the original PageRank formula assume it’s around 15%. So ~15% of your old pages PageRank will be lost because of the 301 redirect, this could have a negative impact on the SERPs the old page used to have. See the Matt Cutts video below for confirmation

What percentage of PageRank is lost through a 301 redirect?

WordPress 301 Redirects

WordPress includes some 301 redirect capabilities built in, for example when a site uses SEO Friendly Permalinks the dynamic version of a URL is automatically 301 redirected to the SEO friendly version.

For example this article can be accessed via it’s SEO unfriendly dynamic URL here : WordPress Automatic Permalinks 301 Redirects.

Hoverover the link above and you can see the URL is: https://stallion-theme.co.uk/?p=511 now click the link and it loads the page you are on now. That’s a built in WordPress 301 redirect in action.

The above is built into WordPress since version 3.3, so no need to worry about 301 redirects when changing WordPress permalinks from the default ?p=123 to the SEO recommended /%postname%/ on a new or even an old site that’s used the default Permalinks setting for years, WordPress 301 redirects automatically (don’t forget on an old site about the ~15% 301 redirect dampening factor).

Changing WordPress Permalinks 301 Redirects

WordPress does NOT handle automatic 301 redirects if you change permalinks from a non-default structure to another.

For example if your site is currently running with the

“Month and Name” option set – outputs URLs like: https://stallion-theme.co.uk/2014/02/sample-post/

and want to change to the SEO recommended permalinks structure

“Post Name” option set – outputs URLs like: https://stallion-theme.co.uk/sample-post/

WordPress SEO Permalinks

The old URLs will NOT automatically 301 redirect to the new, to make this change you’ll either have to manually setup 301 redirects via your .htaccess file or install a 301 Redirect WordPress Plugin. I’ve used both options, really depends on the site and number of posts that require 301 redirects.

WordPress 301 Redirect .htaccess

Unless you are running a WordPress plugin or other way to edit your root .htaccess file, use an FTP program (Filezilla for example) to download your .htaccess file (the .htaccess file is normally where the wp-config.php file is).

Load the .htaccess file in a text editor (Notepad for example) and if you setup SEO Friendly Permalinks as described in an earlier WordPress SEO tutorial it should include this code (this deals with the SEO friendly permalinks):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

If you use a WordPress caching plugin like WP Super Cache or W3C Total Cache you’ll find a lot more rules in your .htaccess file.

All the .htaccess rules mentioned later should be added ABOVE the WordPress permalink rules and anything added by caching plugins like so (the top two lines are 2 simple 301 redirects):

Redirect 301 /old-page.htm https://stallion-theme.co.uk/new-page/
Redirect 301 /another-old-page.htm https://stallion-theme.co.uk/new-page-2/
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

After adding your 301 redirect rules upload the .htaccess file to the root of your site using an FTP program.

.htaccess Simple 301 Redirect

Below is a simple 301 redirect that would be added to the .htaccess file found in the root of your site.

RewriteEngine On
Redirect 301 /old-page.htm https://stallion-theme.co.uk/new-page/

“RewriteEngine On” probably won’t be needed, it’s already been added by WordPress when you turn SEO friendly permalinks on (see earlier). For non WordPress users the above is all you need within your .htaccess file to redirect one page to another.

If I added the above rule to this sites .htaccess file it would redirect

https://stallion-theme.co.uk/old-page.htm to https://stallion-theme.co.uk/new-page/

If I added the rule to another site for example http://domain.co.uk/ it would redirect

http://domain.co.uk/old-page.htm to https://stallion-theme.co.uk/new-page/

This 301 redirect rule type can be used to redirect entire sites one page at a time, this is not the easiest way to redirect a site you’ve moved, but it’s possible:

Redirect 301 / https://stallion-theme.co.uk/
Redirect 301 /page-1/ https://stallion-theme.co.uk/page-1/
Redirect 301 /page-2/ https://stallion-theme.co.uk/page-2/
Redirect 301 /page-3/ https://stallion-theme.co.uk/page-3/

This would redirect the home page / of the old site to the home page / of the new domain, page-1 on the old site to page-1 on the new domain etc… This is not the easiest way to achieve this (see next .htaccess 301 redirect rules for the easy way), but it can be useful if you split an old site over multiple domains for example where wildcard rules just won’t work or you’ve changed the URL structure.

Moving a WordPress Blog with NON-WWW to WWW Support 301 Redirect Rules

Moving a WordPress blog from one domain to another when you keep the same WordPress permalinks settings is easy, after moving domains add a .htaccess file that contains the following rules:

RewriteCond %{HTTP_HOST} ^old-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [L,R=301]

The rules above 301 redirects everything under old-domain.com and www.old-domain.com to www.new-domain.com keeping the original filenames (based on the permalinks settings).

For example the URLs old-domain.com/page-1/ and www.old-domain.com/page-1/ will both 301 redirect to www.new-domain.com/page-1/ on the new domain.

Another alternative is:

RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]

Moving a WordPress Blog with WWW to NON-WWW Support 301 Redirect Rules

As above, except redirecting to the non-www version of the new domain:

RewriteCond %{HTTP_HOST} ^old-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [L,R=301]

For example the URLs old-domain.com/page-1/ and www.old-domain.com/page-1/ will both 301 redirect to new-domain.com/page-1/ on the new domain.

Another alternative is:

RewriteRule (.*) http://new-domain.com/$1 [R=301,L]

WordPress SEO Tip: When moving domains don’t forget to set the preferred domain (www or non-www) under Google Webmaster Tools, so Google knows which www or non-www should be indexed and ranked.

Stallion Responsive SEO Super Comments URLs 301 Redirect Rules

I moved half a dozen posts with over 100 comments between them from one site to another (to this site, it’s some of the WordPress SEO Tutorials: decided to bring all my WordPress SEO Tutorial articles under one domain) and because I use the Stallion Responsive Theme SEO Super Comments feature I had to take into account the comments that were indexed in their own right: although there’s only half a dozen articles, the 100 or so comments meant I had to deal with dozens of URLs with query strings (?cid=123) that needed 301 redirects.

Easiest way to deal with this was a small set of custom 301 redirect rules added to the .htaccess file of the site I was moving the articles from. I’ve pasted one of the custom rules below (there’s a set like this for each article moved):

RewriteCond %{QUERY_STRING} ^cid=([0-9]*)$
RewriteRule ^seo-tutorial-for-wordpress https://stallion-theme.co.uk/seo-tutorial-for-wordpress/? [R=301,L]
RewriteRule ^seo-tutorial-for-wordpress(.*)$ https://stallion-theme.co.uk/seo-tutorial-for-wordpress/ [R=301,L]

No way I could generate this rule via a WordPress 301 Redirect Plugin, it’s too specific to that sites needs. What it does is look for URLs with a query string ?cid=123 (this is what you find on the end of Stallion SEO Super Comment URLs). Looks for URLs including seo-tutorial-for-wordpress (which is the WordPress slug of an article I moved) and 301 redirects it to https://stallion-theme.co.uk/seo-tutorial-for-wordpress/ (where I moved the WordPress SEO Tutorial article to).

Since the cid=number is the comment ID and when moving comments from one site to another WordPress doesn’t maintain the original comment ID (comments get a new comment ID) the above 301 redirects all URLs with format seo-tutorial-for-wordpress?cid=123 from the old site to https://stallion-theme.co.uk/seo-tutorial-for-wordpress/ on the new site.

Most WordPress users will never need a 301 redirect .htaccess rule like the one above, but it shows what you can achieve with the right 301 redirect rules.

David Law

David Law > AKA SEO Dave
*
: 20+ Years Experience as a Freelance SEO Consultant, WordPress SEO Expert, Internet Marketer, Developer of Multiple WordPress SEO Plugins/SEO Themes Including the Stallion Responsive Theme (tested to WordPress 4.8.1 August 2017).

Website - SEO Tutorial for WordPress