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.

6
  • Do you have actual content on the file system at /var/www/exampledomain.com?
    – ernie
    Sep 11 '13 at 14:47
  • Yes there is a working WordPress site there.
    – webworm
    Sep 11 '13 at 14:47
  • Where did you put that config? Is it within a file inside sites-enabled?
    – Bob
    Sep 11 '13 at 14:50
  • It is located in /etc/httpd/conf/vhosts/vhosts.conf. I have included this file in the httpd.conf
    – webworm
    Sep 11 '13 at 14:52
  • What do your Include lines look like? What does the log show? Have you restarted apache?
    – ernie
    Sep 11 '13 at 15:05
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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.