Question

How to redirect mydomain.com to linktr.ee/mydomain ?

  • Posted on September 6, 2023
  • DNS
  • renatovAsked by Renato

My main objetive is to redirect mydomain.com to lintr.ee/mydomain. I have my account at linktree all set up. I’ve already bought mydomain.com and set Godaddy’s Name Servers to look for Digitalocean’s DNS for directions. I’ve also used Digitalocean’s DNS to create a “CNAME” entry to redirect WWW to @. But now I’m stuck because an “A” entry will only let me specify an IP or a resource that I own on Digitalocean. What should I do? How do I redirect mydomain.com to my linktree link using Digitalocean DNS config?

PS: this is just a temporary redirect while I create my site


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.

KFSys
Site Moderator
Site Moderator badge
September 6, 2023

Heya,

While you can use DNS to create an alias with a CNAME record (like making www.mydomain.com point to example.otherdomain.com), DNS by itself doesn’t handle HTTP redirects (like redirecting users who visit mydomain.com to lintr.ee/mydomain). You need a Droplet and a WebService like Apache or Nginx to do that.

Set up a DigitalOcean Droplet:

  • Create a small droplet.
  • Install Nginx on it. If it’s an Ubuntu droplet, you can use:
sudo apt update
sudo apt install nginx

Nginx Configuration:

  • Edit the default Nginx configuration or create a new one. For simplicity, you can edit the default:
sudo nano /etc/nginx/sites-available/default

Remove the current server block and replace with the following:

server {
    listen 80;
    server_name mydomain.com www.mydomain.com;
    
    location / {
        return 301 http://lintr.ee/mydomain;
    }
}

Set A Record:

-   In DigitalOcean's DNS management, set an "A" record for `mydomain.com` (and `www.mydomain.com` if desired) to point to the IP address of the droplet you just set up.

Finalize:

-   Wait for DNS propagation. Depending on various factors, it may take anywhere from a few minutes to 48 hours (usually on the shorter side if it's a new domain).
-   Now, when you visit `mydomain.com`, it should redirect to `lintr.ee/mydomain`.

Note on HTTPS: If you plan to use HTTPS for mydomain.com, you’ll need to set up a certificate (e.g., using Let’s Encrypt) and adjust the Nginx configuration accordingly.

While the above process requires maintaining a droplet, it gives you flexibility. Once you have your website ready, you can reconfigure the Nginx server to serve your website instead of redirecting to Linktree.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel