I have a website which can be reached through www.example.com. Now I want to make it also accessible under example.com. How can I make this?
I have several subdomains e.g. test.example.com, test2.example.com etc.
I also read a bit and found out that one should use htaccess to permanently redirect from example.com to www.example.com.
RewriteCond %{http_host} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
So now there should no duplicate content and it should be SEO friendly. But how do I have to create the A-record? Now there is only one with www.example.com. If I create one with example.com it will automatically mapped to example.com.example.com ...
Then I have to add an entry in the host-file. Does this look like this?
192.168.1.1 example.com
Than I have some entries for the VirtualHost for apache. Is this file correct?
<VirtualHost 192.168.1.1:80>
ServerName www.example.com
ServerAlias *.www.example.com
ServerAlias example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/path
<Directory /var/www/html/path>
AllowOverride None
Options +FollowSymLinks -Indexes -Includes +Multiviews +ExecCGI
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
Solution:
<VirtualHost 192.168.1.1:80>
ServerName example.com
Redirect 301 / http://www.example.com/
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerName www.example.com
ServerAlias *.www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/path
<Directory /var/www/html/path>
AllowOverride None
Options +FollowSymLinks -Indexes -Includes +Multiviews +ExecCGI
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
I made this together with two A-records (one for www.example.com and example.com) pointing to the IP-Adress where the webserver resides. Additionally, I had the following entry in /etc/hosts
192.168.1.1 www.example.com example.com
I also state my whitelist-entry from squid:
.example.com