mvokal
By:
mvokal

Transferring existing droplet to subdomain on another droplet

February 9, 2016 879 views
DNS

Hi, I have two droplets that are each currently accessed through their own domains (let's called them domainA and domainB). However, I would like to merge the domains so that the droplet accessed via domainB is a now accessed as a subdomain of domainA.

I created an A record for a subdomain for domainA, and when I navigate to subdomain.domainA.com it successfully takes me to the site hosted on domainB's droplet. However, the url in the browser changes to domainB.com instead of staying subdomain.domainA.com. What should I do to make sure the url displays correctly?

Additionally, I will likely keep domainB around for awhile in case old users try to return to it, but I would like it to redirect to subdomain.domainA.com. However I still want to keep the subdomain on a different droplet so I don't have to change all the db references and such in my code.

Thanks!

3 Answers

Your web server configuration is what you want to look into to stop the URL being rewritten. Or it's possibly a setting of the application you're hosting. It is unrelated to DNS.

  • Thanks for the help! It turns out there was a redirect to the old domain in the config file, but once I changed that the subdomain works correctly. However, when I navigate to the old domain in the browser I can't figure out how to get it to redirect to the subdomain. I'm doing this in the config file with no luck:

    <VirtualHost *:80>
    ServerName subdomain.domainA.com
    Redirect permanent / https://subdomain.domainA.com/
    </VirtualHost>

    <VirtualHost _default_:443>
    ServerAdmin xxx@yyy.com
    ServerName subdomain.domainA.com:443

        [SSL certificates for subdomain]
    

    </VirtualHost>

    I tried giving it a ServerAlias for the old domain, but that doesn't work either.

    • Be careful, Permanent Redirects are permanent. This means most of the time they cannot be used for testing unless you completely clear your browser's cache between every test. You should test using a temporary redirect, and make it permanent once it works.

      I really can't diagnose configs that are censored because they contain no useful information that can be relied on for troubleshooting.

      • Okay, thanks! I switched to temporary redirects and that helped me debug the issues I was having.

Hi, there are several places you might have to set it:

  • DNS (Like you did with A-name)
  • The server (NGINX or Apache)
  • CMS (your content management system might have settings for homepage URL and might have saved links to images in posts which are not relative).

If you have wordpress and change domain I believe you have to do some updates at least in inline links between posts, unless they are relative (which they often are not). There are often plugins to do such tasks or you can of course do it in sql queries with updates (with replace). But if you do that, please remember to take backups first :-)

You can of course make a copy of your website and copy your db and fix it in a copy... Then you set the subdomain of domain A to point to the new copy of your webpage. Then when everything works fine with the subdomain webpage, you just make a 301 redirect (permanently moved) from the old domain to the new. Google and others will respect your 301.

For anyone reading this in the future, I had to modify my default-ssl.conf file in the server that I want the subdomain to point to as follows:

<VirtualHost *:80>
    ServerName subdomain.domainA.com
    Redirect permanent / https://subdomain.domainA.com/
</VirtualHost>  

<VirtualHost *:443>
    ServerAdmin xxx@yyy.com
    ServerName subdomain.domainA.com:443

    DocumentRoot /path

    #SSL certificates for subdomain.domainA.com
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin xxx@yyy.com
    ServerName domainB.com:443
    Redirect permanent / https://subdomain.domainA.com/

    DocumentRoot /path

    #SSL certificates for domainB.com
</VirtualHost>

Since I used permanent redirects it was important to make sure that I had the SSL certificates for both the old domain and the new subdomain as many users' browsers were redirecting them to https://domainB.com.

Have another answer? Share your knowledge.