Redirect all requests to the a preferred domain

Redirect_arrow.svgIn many cases a website or web application should be accessible by multiple domains.  The Problem is, that google could treat that as duplicated content (https://support.google.com/webmasters/answer/66359?hl=en) and also the trust is divided between all domains.  That’s why google suggests to choose a preferred (canonical) destination URL and to redirect all requests to the a preferred domain (https://support.google.com/webmasters/answer/93633?hl=en).

To achieve that, you can add the following snippet to  your .htaccess or Apache config file:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # 301 redirect for all other domains different from www.ask-sheldon.com or admindomain.ask-sheldon.com
  RewriteCond %{HTTP_HOST} !www.ask-sheldon.com$ [NC]
  RewriteCond %{HTTP_HOST} !admindomain.ask-sheldon.com$ [NC] # you can accept multiple domains -> but attention!!! -> avoid duplicated content

  RewriteRule ^(.*)$ http://www.ask-sheldon.com/$1 [L,R=301]
</IfModule>

This is also useful to took over old domains trust to a new domain.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.