fekri 998
fekri 998

Reputation: 33

best practice for prevent double content google error

in my google search console it says that I have a double content error, page of www with none www.

In .htaccess file I put this code:

RewriteRule ^(.*)$ https://example.com/$1 [R,L]

I tried with the code above to redirect any page to none www , Could you please help to solve the issue .

Upvotes: 1

Views: 35

Answers (1)

MrWhite
MrWhite

Reputation: 45914

RewriteRule ^(.*)$ https://mywebsite.net/$1 [R,L]

By itself this will create a "redirect loop". You need to first check that the request is for www before redirecting. For example:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [R=302,L]

This also needs to be placed near the top of the .htaccess file, before any other rewrites.

Change to a 301 when you have confirmed it works OK.

However, this might only be masking more serious internal errors on your site... why was the "duplicate content" detected by GSC in the first place? Check your internal links, XML sitemap, rel="canoncial" link element etc.

Upvotes: 1

Related Questions