My site not working when "www" is not used, but it's ok with the "www"

Hello, everyone!
When I type in the “”, I can access my site with no problem.
The problem is when I don’t type the www, the site won’t work, leading me to the “APache2 Ubuntu Default Page”.

I tried to force redirection via .htaccess, by including this:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Restarted Apache, with no luck. The problem persists.

I have to tell you all, before that, I was getting a Certificate Error, and then I put this first line in my apache2.conf:


The certificate problem was vanished, but I can’t access my site without the “www”.

Can you help me solve the problem? I believe there’s to ways to solve it: by .htaccess redirection or by some configuration on apache2.conf, but no idea what to do.
Thank you!

Edit: I’m using Ubuntu 14.04, webmin 1.801, Virtualmin 5.03, Intel® Xeon® CPU E5-2620 v3 @ 2.40GHz, 4 cores

Your Apache config is not configured correctly. You should take a look there especially under virtual server configuration.

The solution was to change “Servername mydomain.tld” to “Servername localhost” in the apache conf.
Thank you so much for helping!