Software Engineering

How to forward root domain to www in GoDaddy with full URL?

1 Answer
1 answers

How to forward root domain to www in GoDaddy with full URL?

1
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.

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
app.get('/*', function(req, res, next) {
  if (req.headers.host.match(/^www/) !== null ) {
    res.redirect('http://' + req.headers.host.replace(/^www\./, '') + req.url);
  } else {
    next();     
  }
})
Wrote answer · 7/18/2022
Karma · 1435

Related Questions

How to fix @nestjs/mongoose model dependecy injection error in latest update?
The average is called .............. in statistical language?
यथाशक्ती, पाऊसपाणी या सामातजक शब्दाांचा करून प्रकार तलहा (२)?
What are ingredients?
Instagram like Indian app?