Software Engineering
How do I forward a root domain to 'www' in GoDaddy while preserving the full URL?
2 Answers
2
answers
How do I forward a root domain to 'www' in GoDaddy while preserving the full URL?
1
Answer link
There are several posts on Godaddy support forum, mentioning about using the subdomain forwarding in 'Manage DNS' section to forward example.com to www.example.com. The forwarding only works if you exactly type example.com in address bar.
if (req.headers.host.match(/^www/) !== null ) {
res.redirect('http://' + req.headers.host.replace(/^www\./, '') + req.url);
} else {
next();
}
})
But that feature does not work in following cases:
- If your URL is more than a domain name. e.g. example.com/xyz will not get forwarded to www.example.com/xyz
- If you type https://example.com it will not be forwarded to https://www.example.com
If you want the above cases to work, GoDaddy wants you to host your website on their own Hosting platform, so if you are AWS/Google Cloud/Azure/Digital Ocean customer, then you are out of luck with the domain forwarding option in GoDaddy.
How to fix it:
- Remove the subdomain forwarding from GoDaddy's Manage DNS.
- Add A record with @ entry, pointing to the IP address of your hosting server(from where you serve your website)
- Implement the URL handling/forwarding in your website
You need to handle all the root to www traffic on your own, where you have hosted your website. And there are several ways to host your website, so it would depend on how you have implemented your deployment. Here are a couple of examples
- If you are using Kubernetes with ingress controller, then you can add this annotation to your ingress resource: nginx.ingress.kubernetes.io/from-to-www-redirect: "true", more details here: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#redirect-fromto-www
- If you have plain nginx server then you can redirect the root domain to www using something like: https://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www
- If you are not using any load balancers or reverse proxies then you have to redirect the requests in your web server itself. Node.js express example can be written something like:
if (req.headers.host.match(/^www/) !== null ) {
res.redirect('http://' + req.headers.host.replace(/^www\./, '') + req.url);
} else {
next();
}
})
0
Answer link
To forward your root domain (e.g., example.com) to the 'www' subdomain (www.example.com) in GoDaddy while preserving the full URL, you need to use a forwarding with masking approach.
Here's how to do it:
-
Log in to your GoDaddy Account: Go to the GoDaddy website and sign in to your account.
-
Navigate to your Domain Management: Go to the "My Products" page and find the domain you want to forward. Click the "DNS" button next to your domain to access the DNS Management page.
-
Forwarding Settings:
- In the Domain settings page, look for the 'Forwarding' Section, it will often be below all your DNS records.
- Click the 'Add' button under 'Forwarding'.
-
Set up the Forward:
- Select 'HTTPS' for the forwarding to protocol if you have SSL/TLS certificate installed, otherwise use 'HTTP'.
- In the 'Forward to' field, enter your full 'www' subdomain URL (e.g., https://www.example.com if you use a SSL/TLS certificate).
- Select 'Forward with masking'.
- Fill in the settings for:
- Title: The title you want to appear in the browser tab.
- Description: A brief description of your website for search engines.
- Keywords: Keywords related to your website, separated by commas.
-
Save your settings: Save the forwarding settings and wait for the changes to propagate. DNS propagation can take up to 48 hours, but it's usually faster.
Important Considerations:
- DNS Propagation: Remember that DNS changes can take some time to propagate across the internet. Be patient and allow up to 48 hours for the forwarding to take effect.
- SSL Certificate: If you have an SSL certificate installed on your 'www' subdomain, ensure you forward to the HTTPS version of the URL.