00 Votes

Duplicate Content: Always Redirect Website to WWW

Tip by Stefan Trost | Last update on 2023-01-27 | Created on 2012-04-20

Anyone who deals with websites should know the problem: search engines do not like duplicate content.

However, most websites can be accessed under both addresses example.com and www.example.com. As a result, any content is held twice - once on example.com/content and another time on www.example.com/content - and already we have double content accessible on the net without maybe having noticed it at all.

Moreover, the assignment and the link structure is ambiguous with this. Some visitors are using your website with www, others without www. Problems may occur, for example, whenever a user logs in without "www" and then changes to the www version by clicking a link and is maybe logged out with this action, because the user is only logged in in one of the versions.

The Solution

The solution for this problem is implemented quickly and easily. Just write the following lines into your htaccess file, replacing example.com with the domain of your website:

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

This is what happens: All requests without www (Rewrite Condition in the second line) will be redirected to the version with wwww (third line). The ^(.*)* and the $1 ensure that whatever was written behind the domain is kept. Simultaneously, a search engine friendly 301 Permanent Redirect is created, so that the search engine knows that the content in question is now available elsewhere and also stays there. Instead of "https" we can of course also write "http" if our website does not have a HTTPS certificate.

If you now enter example.com/content in your browser, the request is automatically redirected to https://www.example.com/content and the URLs are clean.

ReplyPositiveNegative

About the Author

AvatarYou can find Software by Stefan Trost on sttmedia.com. Do you need an individual software solution according to your needs? - sttmedia.com/contact
Show Profile

 

Related Topics

The Askingbox Search

Info | 0 Comments

HTACCESS: Simplify URL

Tutorial | 0 Comments

How to avoid Spam Mails

Tip | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.