Question

Transferring existing droplet to subdomain on another droplet

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!


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.

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.

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.