ServerName/ServerAlias in virtual host configuration

1

I have a VPS on which I am running Apache 2 (CentOS v5). I have my DNS setup as follows ...

(A Record) exampledomain.com points to 123.456.789.123
(CName Record) www.exampledomain.com points to exampledomain.com.

My question is what ServerName and ServerAlias values do I use in my Virtual Hosts configuration file so that visitors will be directed to my website whether they use www.exampledomain.com or exampledomain.com. Ideally I would like the hostname of the server to be reported as www.exampledomain.com.

I have this currently but I find it directs the user to the Apache default page. I am trying to follow the directions at the Apache Documentation site but I must be messing something up.

<VirtualHost *:80>
    ServerAdmin admin@exampledomain.com
    DocumentRoot /var/www/exampledomain.com
    ServerName exampledomain.com
    ServerAlias *.exampledomain.com
    ErrorLog /var/log/exampledomain.com-error-log
    CustomLog /var/log/exampledomain.com-access-log common
</VirtualHost>

Any example of what I am trying to acheive would be Google. Regardless of if I type google.com or www.google.com the URL changes to www.google.com.

webworm

Posted 2013-09-11T14:45:15.443

Reputation: 551

Do you have actual content on the file system at /var/www/exampledomain.com? – ernie – 2013-09-11T14:47:00.357

Yes there is a working WordPress site there. – webworm – 2013-09-11T14:47:38.500

Where did you put that config? Is it within a file inside sites-enabled? – Bob – 2013-09-11T14:50:17.873

It is located in /etc/httpd/conf/vhosts/vhosts.conf. I have included this file in the httpd.conf – webworm – 2013-09-11T14:52:11.377

What do your Include lines look like? What does the log show? Have you restarted apache? – ernie – 2013-09-11T15:05:18.340

Are you saying that the config looks correct? – webworm – 2013-09-11T15:07:16.007

Answers

0

You will also need a RewriteCond and a RewriteRule

RewriteCond %{HTTP_HOST}   !^(www|s.\.www|m)\.nimblex\.(net) [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.nimblex.net/$1 [L,R]

Bogdan

Posted 2013-09-11T14:45:15.443

Reputation: 277