What is "duplicate content"?
"Duplicate content" is simply where you have two or more different URLs referencing essentially the same resource and are not canonicalising this in some way (eg. with a rel="canonical"
element or external redirect). https://example.com/foo/bar
and https://www.example.com/foo/bar
are two different URLs and are consequently treated differently when setting cookies, client-side caches and search engines. Whilst these two URLs might return the same content on your site (and indeed most sites), technically they might not, so do need to be treated differently.
In terms of SEO, search engines might end up (unnecessarily) dividing crawl budget between the two URL versions. They might choose to favour the non-canonical (ie. non-preferred) URL over the other when returning results in the SERPs. You may get backlinks to both URLs which will potentially divide so called "link juice" between the URLs which could result in neither page ranking as well as if you only have one canonical URL for one resource.
Having said that, search engines can often resolve www vs non-www duplicate content issues themselves, providing there is a strong enough signal. But they can still get it wrong.
Resolving "duplicate content"
You can potentially get a duplicate content issue if you are inconsistently linking (or referencing) both example.com
and www.example.com
throughout your site.
- If you are using absolute URLs in your internal links then you need to consistently link to www or non-www. OR, use root-relative URLs starting with a slash and omit the scheme and hostname entirely.
rel="canonical"
link element in the head
section of your HTML needs to reference the canonical hostname.
- XML sitemap needs to reference the canonical hostname.
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
From this HTTP to HTTPS redirect, I assume your canonical hostname uses the www
subdomain? If www
is not your canonical hostname then that's obviously an error and should be fixed.
(If you have tested that this is working as expected then this should be a 301 - permanent - redirect, as opposed to a 302 - temporary - redirect, which is what this is currently defaulting to. ie. Change R
to R=301
in the RewriteRule
flags argument.)
Once you have confirmed/fixed the steps mentioned above then you can implement a non-www to www 301 external "redirect" in your .htaccess
file to resolve any URLs that might have been indexed on the non-canonical hostname.
UPDATE: The redirect ensures that only the canonical URL (the www variant in this case) is viewed by users and crawled by search engine bots.
For example, after the HTTP to HTTPS redirect above:
# Redirect example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
TIP: Always test first with 302 (temporary) redirects to avoid potential caching issues, since 301s are cached persistently by the browser.