TransWikia.com

Duplicate content from www and non-www

Craft CMS Asked by Alex Carpenter on May 27, 2021

I am getting duplicate content issues because both www and non-www are being loaded.

My htaccess has the standard force https as all my other sites but it isn’t working.

# START Force https
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteCond %{HTTP_HOST} ^(www.)?geniusesforhire.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.geniusesforhire.com/$1 [R=301,L]
# END Force https

Could anything in Craft be causing this or is anything in Craft able to fix this?

2 Answers

2 options to avoid duplicate content:

  • add a canonical tag to your HTML
  • redirect non-www to www or vice versa

Answered by Matthias Redl-Mann on May 27, 2021

Your Apache redirect rule is only redirecting http -> https.

You also want a rule to redirect non-www hits to the www version.

Something like:

RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ https://www.geniusesforhire.com/$1 [R=301,L]

As Matthias mentions in his answer, I'd also put a link tag somewhere in the head of your Twig template. Assuming craft's entry variable is available:

{% if entry is defined %}<link rel="canonical" href="{{ entry.url }}">{% endif %}

Answered by RitterKnight on May 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP