We’ve been building out content fast and furious lately, always with an eye towards SEO. However, we recently discovered a problem in the technical SEO on one of our sites. An audit using the tools at SEMRush showed the potential for a duplicate content penalty from Google.  Here’s how you prevent Google and the other search engines from dinging you for duplicate content on a WordPress website.

First, CHOOSE how you will serve your website, either using the natural URL or the WWW subdomain.  For example, choose either https://blueskydigitalstrategy.com/ OR https://www.blueskydigitalstrategy.com/  Both are valid.  But, if you don’t tell Google which one you want to use AND you don’t redirect the one you don’t want to use to the one you do, both will be indexed as unique sites.  Voila, you have duplicate content.  Furthermore, Google will distribute your website’s “juice” between the two “sites,” effectively diluting your killer content and making it harder for you to rank.  All that keyword research will be rendered useless.  Try Googling “canonical programming” if you want to know more.

Once you’ve made your choice, TELL Google which one you prefer.  This means going into your Google Search Console, adding both versions of the website (and the http:// and https:// versions, too), verifying your ownership, and selecting the one you prefer (e.g. https://blueskydigitalstrategy.com).  You’ll typically have four separate properties in the GSC, so group them into a property set.  A property set will show you aggregate data for all its member properties.  Select a single website property within the property set, and then click on the gear symbol in the upper right of your GSC.  In the dropdown menu, select “Site Settings.”  This will give you the option to select a “Preferred domain” (or no preference; don’t do this).  When Google finds a link back to your site such as http://www.example.com, it will consider it exactly the same at http://example.com, or vice versa.

Avoid Duplicate Content Penalty

To Force Non-WWW

 

To create a 301 (permanent) redirect to the non-WWW version of your site, you’ll need to insert the following code (http://www.example.com redirects to http://example.com):

 

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
# Force non-www (MUST be ABOVE WordPress RewriteRules) #
RewriteCond %{HTTP_HOST} ^(www.) (.*) [NC]
RewriteRule ^ http://%2%{REQUEST_URI} [L,R=301]
or
# Force non-www (MUST be ABOVE WordPress RewriteRules) #
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*) http://example.com/$1 [L,R=301]

RewriteBase /
... </IfModule>


To Force WWW

 

To create a 301 (permanent) redirect to the WWW version of your site instead, you’ll need to insert the following code (http://example.com redirects to http://www.example.com):

 

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
# Force www (MUST be ABOVE WordPress RewriteRules) #
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
or
# Force www (MUST be ABOVE WordPress RewriteRules) #
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Rewrite /
... </IfModule>

Now you’re ready to test your configuration.  Just plug the URL to be redirected into your browser of choice.  If it doesn’t redirect, clear your cache and try again.  Once you’ve got your configuration correct, you’re all set to avoid the Duplicate Content Penalty.

Avoid the Duplicate Content Penalty using Apache httpd.conf

A more elegant way to accomplish the 301 redirect is to modify your httpd.conf file, if you have access to it.  This is an Apache file, so you’ll have to restart Apache to have the changes take effect.  Typically, this file is found under /etc/apache2/sites-enabled/httpd.conf or something similar.  Check with your host for the specifics.  You’ll want to add the following lines to redirect non-www to www:

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent ^/(.*) http://www.example.com/$1
</VirtualHost>

And, you’ll want to add these lines to redirect www to non-www:

<VirtualHost *:80>
     ServerName example.com
     Redirect permanent ^/(.*) http://example.com/$1
</VirtualHost>

Don’t forget to restart Apache via:

sudo service apache2 restart
Call now!