User login

Redirect multiple domain names to single canonical domain for your site

This Apache rule describes how to have all selected domains and subdomains for a site come up in the site visitor's browser address bar as your one chosen canonical domain.

Here is an all-in-one-line approach:

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

On a Drupal site, your .htaccess will already have an IfModule mod_rewrite.c section, so putting these rules in directly below the existing RewriteEngine On line will work.

Here is also a one-at-a-time method:

<IfModule mod_rewrite.c>
  RewriteEngine on

  # Redirect all users to access the site at '' (www prefix).
  RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  RewriteRule ^(.*)$$1 [L,R=301]
  RewriteCond %{HTTP_HOST} ^www\.anotherexample\.com$ [NC]
  RewriteRule ^(.*)$$1 [L,R=301]
  RewriteCond %{HTTP_HOST} ^web\.yetotherexample\.com$ [NC]
  RewriteRule ^(.*)$$1 [L,R=301]
  RewriteCond %{HTTP_HOST} ^ftp\.example\.com$ [NC]
  RewriteRule ^(.*)$$1 [L,R=301]

An implementation that preserves any subdomain while making the domain name consistent:

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.*)\.(activore\.com|activo\.re|actvr\.co) [NC]
RewriteRule (.*)$1

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)\.(activore\.com|activo\.re|actvr\.co) [NC]
RewriteRule (.*)$1


Searched words: 
forward website URL web site domain redirection .htaccess redirect everything to one domain name


Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.