Redirect subdomain to another website

October 3, 2014 10.1k views

Hi - what is the easiest way to set up a subdomain like which I would want to redirect to ? I have tried a few things but cannot get it to work. Thank you!

2 Answers

I may have answered my own question. This approach seems to work, although, there may be a better alternative.

Set up the following DNS entry at     IN      CNAME       @

And then create / modify .htaccess as follows:

<IfModule mod_rewrite.c>
    RewriteEngine on
    Options FollowSymLinks
    RewriteCond %{HTTP_HOST} ^
    RewriteRule ^(.*)$ redirectToGoogle.html [L]

And then create redirectToGoogle.html and forward to the desired site

        <META http-equiv="refresh" content="0;URL=">

  • Cool. I looked around for a solution when I saw your question. most of what I tried didn't work. Nice work.

  • A better option would be creating a separate virtualhost for (see How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS | DigitalOcean) with the following config:

    <VirtualHost *:80>
        Redirect permanent /

    You will still need to create the DNS record, though.

  • kamain7 i tried doing what you suggested with no success. could you assist me?

  • @galvax: Have you restarted Apache after adding the virtualhost?

    sudo service apache2 restart

    Did you create a DNS record for that points to your droplet?

  • That worked! but now, i want to mask the ip address so that instead of redirecting you to the ip address, i want to show the url as a subdomain. To do that i enter this into my DNS records.

    mysubdomain IN A CNAME mysubdomain

    Unfortunately this does not seem to work, Is there something wrong in my configuration? i am aware the ip address i put is a local one (i replaced it).

  • thank you kcristella, that's work.

  • thank you kcristella, that's work.

Have another answer? Share your knowledge.