How do I redirect www.example.com to example.com

Hi there
If this has been answered before I apologize.
I want to make www.example.com redirect to example.com.
Is that something that can be done in the NS records?
Thank you!

1 Reply

This can be accomplished by doing the following:

  1. Creating the appropriate DNS records for the primary domain and www subdomain
  2. Creating a redirection in your specific web server configuration for your website

DNS Records:

Assuming you already have propagated A and Quad-A/AAAA records for example.com, you could either create a new subdomain A/AAAA Record or a CNAME for www. For the sake of simplicity, I might recommend the CNAME over two additional A/AAAA records in case your IP ever changes in the future.

The configuration would something like this in Cloud Manager:

Hostname: www
Alias To: @ (root/primary domain)
TTL: Default or specified time

Keep in mind that DNS propagation is not immediate, so subsequent steps may require a slight pause before continuing. I'm a personal fan of using DNS Checker to view global propagation after making changes to any of my domains.


Web Server Redirect:

Your web server's server block needs to be configured to redirect www to the primary domain (or visa versa depending on preference). The configuration will differ between NGINX and Apache, so I've included StackOverflow discussion about both methods:

Assuming that you intend to generate an SSL certificate for HTTPS encryption, you would only really need to create the HTTP block since tools like CertBot/LetsEncrypt generally modify the server block accordingly to enable HTTPS traffic. For more information about how to use this tool, be sure to select your Linux Distribution and web server from the list below:

Once completed, users can securely navigate to your domain using both the primary and www subdomains.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct