A permanent 301 redirect informs search engines and browsers (Firefox, Google Chrome, Microsoft Internet Explorer etc…) a webpage 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 website to here, if a visitor found a link to

https://stallion-theme.co.uk/seo-tutorial/ (old location)

It automatically 301 redirects to

https://seo-gold.com/seo-tutorial/ (new location)

in a browser since there’s a 301 redirect on the old site (added to the .htaccess file) to here.

Simple 301 Redirect Added to Default WordPress .htaccess File
Simple 301 Redirect Added to Default WordPress .htaccess File

Highlighted in blue is a simple 301 redirect added to the top of a default WordPress .htaccess file.

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

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%. ~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?
https://www.youtube.com/watch?v=Filv4pP-1nw

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://seo-gold.com/?p=3955 now click the link and it reloads the webpage 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.

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

For example if your website is currently running with the

“Month and Name” option set – outputs URLs like: https://seo-gold.com/2020/12/sample-post/

and want to change to the SEO recommended permalinks structure

“Post Name” option set – outputs URLs like: https://seo-gold.com/sample-post/

Best WordPress SEO Permalinks Settings
Best WordPress SEO Permalinks Settings

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).

Default WordPress .htaccess File
Default WordPress .htaccess File

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 /
RewriteRule ^index\.php$ - [L]
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 W3 Total Cache you’ll find a lot more rules in your .htaccess file.

If you are having problems creating the WordPress .htaccess file, Download the Default WordPress .htaccess File. This is only suitable for standard WordPress installs, it’s not suitable for multi-site WordPress installations.

Simple WordPress 301 Redirect Rule

Simple 301 Redirect Added to Default WordPress .htaccess File
Simple 301 Redirect Added to Default WordPress .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):

RewriteEngine On
Redirect 301 /old-page.htm https://seo-gold.com/new-page/
Redirect 301 /another-old-page.htm https://seo-gold.com/new-page-2/

# BEGIN WordPress
<ifmodule mod_rewrite.c="">
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
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://seo-gold.com/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://seo-gold.com/old-page.htm to https://seo-gold.com/new-page/

If I added the rule to another site for example https://example.com/ it would redirect

https://example.com/old-page.htm to https://seo-gold.com/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:

RewriteEngine On
Redirect 301 / https://seo-gold.com/
Redirect 301 /page-1/ https://seo-gold.com/page-1/
Redirect 301 /page-2/ https://seo-gold.com/page-2/
Redirect 301 /page-3/ https://seo-gold.com/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 ^(.*)$ https://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 (.*) https://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 ^(.*)$ https://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 (.*) https://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 Search Console, so Google knows which www or non-www should be indexed and ranked.

Http to Https Htaccess 301 Redirect Rules
Http to Https Htaccess 301 Redirect Rules

And since it’s 2020 and a secure site is important, consider updating from http (unsecure) to https (secure) access to your website. Used to be case SSL certificates where expensive, but there are free services like Letsencrypt which offer free SSL certificates: this website runs under a free Letsencrypt SSL certificate.

If you do update from http to https don’t forget any old 301 redirect rules within your .htaccess file will need upgrading from http to https. Otherwise there will be a double redirect which is inefficient. It’s an easy update, simply change the http URLs to https URLs.

Update HTTP 301 Redirect Rules to HTTPS 301 Redirects
Update HTTP 301 Redirect Rules to HTTPS 301 Redirects

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://seo-gold.com/seo-tutorial-for-wordpress/? [R=301,L]
RewriteRule ^seo-tutorial-for-wordpress(.*)$ https://seo-gold.com/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://seo-gold.com/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://seo-gold.com/seo-tutorial-for-wordpress/ on the new site.

I’ve used an even more complex set of 301 redirect rules where after moving WordPress Posts including comments, the comment IDs on the two sites didn’t match up, but I wanted the SEO Super Comments to pass ranking benefit.

RewriteCond %{QUERY_STRING} ^cid=25703$
RewriteRule ^seo-meta-tags/$ https://seo-gold.com/seo-meta-tags/?cid=275 [R=301,L]
RewriteCond %{QUERY_STRING} ^cid=25716$
RewriteRule ^seo-meta-tags/$ https://seo-gold.com/seo-meta-tags/?cid=276 [R=301,L]

RewriteRule ^seo-meta-tags/google-meta-description-tag/ https://seo-gold.com/seo-meta-tags/does-google-use-meta-keywords/? [R=301,L]
RewriteRule ^seo-meta-tags/meta-description-tag/ https://seo-gold.com/seo-meta-tags/meta-description-tag-has-no-direct-seo-value/? [R=301,L]
RewriteRule ^seo-meta-tags/html-meta-tags/ https://seo-gold.com/seo-meta-tags/html-meta-tags/? [R=301,L]

RewriteRule ^seo-meta-tags/(.*)$ https://seo-gold.com/seo-meta-tags/ [R=301,L]

The first line RewriteCond %{QUERY_STRING} ^cid=25703$ looks for a specific rewrite condition which will be used by line two. The condition is find cid=25703 which is a specific SEO Super Comment URL.

The left side of the second line RewriteRule ^seo-meta-tags/$ https://seo-gold.com/seo-meta-tags/?cid=275 [R=301,L] says find the rewrite condition from line one associated with seo-meta-tags/, so specifically looking for a URL including seo-meta-tags/?cid=25703. The right sie of the second line is where the URL should be redirected to, this URL https://seo-gold.com/seo-meta-tags/?cid=275

Lines three and four are for another comment.

Lines 5, 6 and 7 are related to WordPress Attachment Pages. Line five RewriteRule ^seo-meta-tags/google-meta-description-tag/ https://seo-gold.com/seo-meta-tags/does-google-use-meta-keywords/? [R=301,L] is looking for the URL seo-meta-tags/google-meta-description-tag/ and is 301 redirecting it to https://seo-gold.com/seo-meta-tags/does-google-use-meta-keywords/

The final line RewriteRule ^seo-meta-tags/(.*)$ https://seo-gold.com/seo-meta-tags/ [R=301,L] is a catchall for anything else left related to the WordPress Post with URL seo-meta-tags/. The (.*) is wildcard, it means find anything. So this means find seo-meta-tags/ANYTHINGHERE and 301 redirect it to https://seo-gold.com/seo-meta-tags/ where ANYTHINGHERE is dropped. This format could be used to 301 redirect thousands of webpages or just one to a single URL.

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

David Law

*
David Law : Technical SEO Expert with 20+ years Online Business, SEO, Search Engine Marketing and Social Media Marketing experience... Creator of multiple WordPress SEO Themes and SEO Plugins. Interests: wildlife, walking, environmental issues, politics, economics, journalism, consumer rights.

Website - SEO Gold Services