1

My website uses both www.example.com and example.com.

I recently tested for duplicate titles on the website and it seems that any title on a page at www.example.com and example.com is perceived as duplicate by search engines.

Does anyone know how I can use both the www.example.com and example.com without duplication?

3
  • 1
    Are you running two different websites at example.com and www.example.com? If not, you should 301-redirect one version to the other.
    – Zistoloen
    Jun 28, 2016 at 10:02
  • One site. Where do I put the redirect?
    – chell
    Jun 28, 2016 at 11:17
  • I added a new answer to explain you how to do it.
    – Zistoloen
    Jun 28, 2016 at 15:13

2 Answers 2

3

Regarding the comment on your question, you only have one site which is served to your users with the two versions of the site (with www and without www).

Therefore, you need to 301 redirect one version to the others (as you wish). For this, you can use a .htaccess file if you use Apache as a web server (at the root of your site).

For exemple, here the code to redirect all www URLs to no-www URLs:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com [NC]
RewriteRule (.*) http://example.com/$1 [QSA,R=301,L]
</IfModule>

Or the opposite (no-www to www):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
2
  • I'm on Heroku with a Rails environment. I will have to research how to do that then. Thank you very much for you answer. I will make a record of it for when I have an Apache website.
    – chell
    Jun 29, 2016 at 3:31
  • OK, you just need to find which web server you use and look for how to implement 301 redirect with it.
    – Zistoloen
    Jun 29, 2016 at 8:55
2

You have many ways to make it, if you want the users to access both versions with WWW and without, you can use canonical link from one version to the another one. EX: From the non WWW version

<link rel="canonical" href="https://www.example.com" />

If you don't want the users to access any of your pages for example the non WWW version, you can redirect all the pages without WWW to WWW using 301 redirect.

The last option is to add noindex in the for one of your pages

<meta name="robots" content="noindex,follow" >

It depends on your case, choose what fits your website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.