I have a domain - example.com
.
Below are my DNS records.
example.com A IP address
www.example.com A IP address
Here is my Apache virtual host configuration.
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/public_html/www.example.com
</VirtualHost>
Now when I type example.com
(without www
part) in my browser I get default Apache page not file from DocumentRoot
. When I add www
to my domain everything is OK.
Now the question is how to set this up so that both domains www.example.com
and example.com
serve the same file from document root? Should I handle this at DNS level or configure web server somehow? I am noob in all this so the question is probably stupid.
ServerAlias
directive, or to set up a separate virtualhost for the non-www version that 301 redirects to the www version (generally better for SEO).