How to change your app's main domain

2024-01-24

So you are working on your app, it's available online, you have a {YOUR_NUMBER}1 users, and BOOM (!), you found a domain that's better than yours and is available!

For me, when the first wave of excitement washed away, I immediately started thinking about:

In case you have similar concerns about making a smooth transition to the new domain, read on, as I'm documenting this exact process.

What do I need to keep in mind?

  1. Setting up relevant DNS records from your old domain into the new one (e.g. skip records for email of course)
  2. Setting proper2 redirects from your old domain to the new one

I have done this already once when I was switching from from a test subdomain on my personal site to --> betterread.in to (now) --> betterread.org.

I'm lucky (or unlucky) that I don't have a ton of traffic to take care of just yet, but there are some direct links that are quite important to keep working. For some context my web app allows to read Dutch3 articles which can be imported from (almost) any url like so https://betterread.in/import?url=<SOME_URL>. So, some of the links to specific articles proxied through my app have found a way into online Dutch course materials of my lovely wife4, which means that those links better continue working haha.

Lastly, a friendly reminder to always make sure to have a recent backup/snapshot of your whole production server.

Best backup is the one you you have, but never need.

Worst - the one you need but never made.

Source: unknown

Setting DNS records

In theory this should be as simple as just copypasting DNS records from your previous domain. Instructions vary per registrar, pretty sure you can figure this out.

As a minimum, you need 2 DNS records, like so Basic DNS settings screenshot

Setting proper redirects

This one is a bit more involved, since it requires tinkering with your production server setup.

  1. HTTP is redirected to HTTPS
  2. Old domains redirect to new main domain with all the url parameters
  3. Redirect from old domains issues a 301 (Moved Permanently) redirect

For me this looks something like this:

# Catching all ipv4/6 http traffic and making it https
server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name _;
	return 301 https://$host$request_uri;
}

# Redirecting all aliases to current main domain=betterread.org
server {
    server_name olddomain1.com olddomain2.com olddomain3.com;

    location / {
        return 301 https://betterread.org$request_uri;
    }

    listen 443 ssl;
    # a few more lines managed by Certbot
}

# Main domain configuration
server {
    server_name betterread.org;

    # Your existing proxy configuration or other settings
    location / {
        include proxy_params;
        proxy_pass http://unix:/path/to/my/app;
    }

    listen 443 ssl;
    # a few more lines managed by Certbot
}

Lastly, enable SSL for your new domain

I'm happily using Let's Encrypt's service with an extension for nginx.

It manages the certificates, renewal is also pretty easy. It's as simple as launching certbot command, it then parses your nginx config files and suggests for which domains to enable SSL.

Choose your new domain, and voilĂ ! You have SSL-enabled domain.

1

Tens / hundreds / thousands, if it's more than that you probably know what to do already :D

2

By "proper" I mean that all of the url parameters are just passed without change to the new domain. This way, redirect happens seamlessly, and any old links would just work. This is also said to help with helping retain SEO ranks/scores of the previous domain, but it seems like actual experience is not always smooth.

3

Support for more languages coming soon!

4

We run an online Dutch language school - JeDutchy, you can check it out on instagram or youtube