lukecd
By:
lukecd

Multiple Domains for one website

January 19, 2015 978 views

Hi, I setup my main domain picnic.ly and configured it to be associated with a droplet. Then I setup a second domain picnicly.com 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 picnicly.com to automatically redirect to picnic.ly. 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 picnic.ly.

Thanks!

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 picnicly.com or www.picnicly.com to picnic.ly:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^picnicly.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.picnicly.com$
  RewriteRule (.*)$ http://picnic.ly/$1 [R=301,L]
</IfModule>
  • 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.

    https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

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

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

    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.