How can I redirect traffic from an existing subdomain to a new subdomain?

Our company recently went through a rebrand resulting in a change of domain.

We previously had users accessing our app (Ubuntu droplet with NodeJS) via

I have successfully updated the DNS to have the droplet be served on instead (which is working completely fine), but would like anyone who mistakenly goes to the old access point ( to be redirected to the new subdomain (

DNS is being managed through DigitalOcean, and both domains are purchased through Google Domains.

I have tried a CNAME, but I am seeking a true redirect than an alias.

One option I have considered is hosting a LAMP droplet on and use Htaccess to do a 302 redirect, but that seems silly hosting and paying for a droplet just for that purpose.

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.


If you have a webserver like Apache or Nginx installed on your Node Droplet, you could create a separate Vhost or server block for the old domina name and add the redirect there.

If this is not the case, you could try implementing the logic into your Node application directly. You could check if the host matches your old domain name add the redirect to the new one if this is the case.

You could use something like this:

app.use(function forceLiveDomain(req, res, next) {
  var host = req.get('Host');
  if (host === '') {
    return res.redirect(301, '' + req.originalUrl);
  return next();

Personally I would go with the Nginx or the Apache redirect so that I don’t have to change the application logic.

Hope that this helps! Regards, bobby