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 ( 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 (

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 or
  RewriteCond %{HTTP_HOST} !$ [NC]
  RewriteCond %{HTTP_HOST} !$ [NC] # you can accept multiple domains -> but attention!!! -> avoid duplicated content

  RewriteRule ^(.*)$$1 [L,R=301]

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.