Multiple Domains for one website

January 19, 2015 922 views

Hi, I setup my main domain and configured it to be associated with a droplet. Then I setup a second domain and set it up to point to the same ip address. This is all working fine.

What I can't seem to figure out how to do is for to automatically redirect to I bought the .com address in case people were confused as to the domain, but the one we want to appear in the browser window is


1 Answer

You can do this via a rewrite set up on your web server. Assuming that you are using apache you will need to do the following.

1.) In your virtualhost configuration (if you haven't set this up specifically this would be the file /etc/apache2/sites-enabled/000-default.conf) change AllowOverride None to AllowOverride All for your main web root.

2.) Next, enable the rewrite module with the commands:

a2enmod rewrite;
service apache2 restart;

3.) Finally, create an .htaccess file in your web root with the following content. This will redirect any requests for or to

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^$ [OR]
  RewriteCond %{HTTP_HOST} ^$
  RewriteRule (.*)$$1 [R=301,L]
  • cool thanks ... so i found this post about how to create that .conf file and i'm running into a problem that probably me just being new to this.

    When I try to create the .conf file with this command

    cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/

    I get this error ....

    cp: /etc/apache2/sites-available/000-default.conf: No such file or directory

    Anyway, probably some really basic that I'm missing here ... thanks again.

    by Justin Ellingwood
    The Apache web server is the most popular way to serve web content on the internet. Apache has the ability to serve multiple domains from a single server by using a mechanism called "virtual hosts". If a virtual host is configured correctly for each domain, the web server can correctly route traffic to the appropriate files based on the domain name requested. In this guide, we'll demonstrate how to configure Apache virtual hosts on an Ubuntu 14.04 VPS.
Have another answer? Share your knowledge.