Question

redirect from a domain without "www" to the one with "www"

Posted April 17, 2016 22.7k views
DNS

How can I setup my domain so that the main domain will be with “www” and when a user come to the bare domain without “www” they’ll be redirected to the domain with “www” with the status 301 or 302? In the panel of namecheap I can do that, but I’ve changed the nameservers arlready so I have to do that here at digital ocean.

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.

×
2 answers

DNS (Nameservers) cannot cause HTTP Redirects. You have to do it at the webserver level. Separate the bare domain (without www) to a different vhost and have that vhost redirect to the primary vhost. You didn’t specify what webserver you use so I can’t help you more than that.

  • As I said, at namecheap I can do it without it while hosting my website somewhere else and namecheap doesn’t know anything about my webserver, can I do such a redirect here as well?

    At namecheap I meant at the dashboard of my domain, at the domain level that is. Not at a hosting dashboard because I didn’t host my website there.

    • When you did it with Namecheap, they probably hosted a tiny website for you, redirecting the address to the new one, even though you weren’t hosting with them. It is impossible to do at the DNS Layer as DNS Servers don’t even know what port or protocol you’re querying for. - Only the hostname.

Submit an Answer