Website not working on non www

Probelm

Website not working on non www

Solution

In cases where you have an issue issue with with a site not working without www it may be for many reasone but I had this particularly when I tried to install letencrypt SSL it turn out to be the host name which can be found at:

/etc/hosts

it had then name domain.com, this was set up when email server was set up. What I did was to change the host name to www.domain.com and then had the redirect in place in .htaccess

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

so all traffic is redirected to domain.com then installed the certificate.

The other thing to note was that testing this on chrome was very difficult to debug and to know where the issue was as at it was auto completing when typing the domain in the browser, so I used chrome ingonito.