Websites do not load with www

June 14, 2019 167 views
DNS Ubuntu 16.04

I am running multiple Wordpress sites on my server. I can load my sites with just http://sitename.com but they will not load when I use www.sitename.com. I added a DNS CNAME record with www and @ to each website but it redirects to an unavailable page instead of my correct website. It looks like it's redirecting my websites to my DigitalOcean IP Address. How do I fix this?

1 Answer

Hi,

There are typically two configurations required to do what you want to do:

  1. the www DNS needs to resolve to the same IP as the websites, typically your Droplet IP or another domain that resolves to your Droplet IP
  2. your web server configuration (apache or nginx typically) needs to perform a redirect when a site is requested for

From your description of the problem, it sounds like your DNS is setup correctly but the second part, the part that will redirect the www request to the right site, is not.

This past answer has some of the webserver configuration info for Apache and Nginx (right after):

https://www.digitalocean.com/community/questions/how-can-i-redirect-www-mysite-com-to-mysite-com-using-digitalocean-dns?answer=13333

Both of these examples are for a virtual host that listens for the www domain and then redirects it to the non-www version of the site domain. A "301" redirect is a "permanent" redirect (for search engine purposes).

If you're still stuck and you are using Apache, here is a DigitalOcean tutorial that uses an A record instead of a CNAME - reviewing these steps might help with your issue.

https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-apache-on-ubuntu-14-04

Here's another tutorial on redirects that includes some nginx info too:

https://www.digitalocean.com/community/tutorials/how-to-create-temporary-and-permanent-redirects-with-apache-and-nginx

If you are stuck, please reply with a little more information like which web server are you using (apache or nginx, for example).

Hope this helps and good luck!

by Justin Ellingwood
HTTP redirects are used to redirect web site visitors to new locations when they request content. These are useful for a variety of reasons, whether permanent or temporary. This guide will demonstrate how to redirect visitors using Apache and Nginx.
Have another answer? Share your knowledge.