I now have the following:

<VirtualHost *:80>
ServerName www.companyname.com
DocumentRoot /www/html/www.companyname.com/

<VirtualHost *:80>
ServerName test.companyname.com
DocumentRoot /www/html/www.companyname.com/test/

Which does not work when I type into the browser


However, when I restart apache, I get a message saying

Stopping httpd:                                            [  OK  ]
Starting httpd: [Tue Apr 05 10:49:48 2011] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
                                                           [  OK  ]


How do I configure apache so I can have many sub domains along with my main domain?

for example, google has

www.google.com mail.google.com docs.google.com

how do I do the same, but get the sub domain to go to a different directory and or web page on the website?

We use a LAMP configuration on RedHat linux.


Set up multiple VirtualHosts with a different ServerName and DocumentRoot for each.

<VirtualHost *:80>
    ServerName   www.example.com
    DocumentRoot /var/www/www.example.com/
    # ... other directives ...

<VirtualHost *:80>
    ServerName   subdomain.example.com
    DocumentRoot /var/www/subdomain.example.com/
    # ... other directives ...

I encourage you to have a look at your existing config files (which are under /etc/httpd/ on RedHat, I believe), and have also to have a look at Apache's documentation.

  • This does not seem to work. Do I need to restart apache for the changes to take effect? – oshirowanen Apr 5 '11 at 9:16
  • Yes, I had to restart, but when I do and even though it restart fine, I get a link broken message when I try to go to the website. – oshirowanen Apr 5 '11 at 9:29
  • Please see update 1 in original question. – oshirowanen Apr 5 '11 at 9:52
  • Have you set up your A-records correctly to point to your server? What does happen when you type the address into your browser (i.e. more specific than it "does not work")? – nickgrim Apr 5 '11 at 16:20

If someone types http://sub1.domain.com then it will point to http://domain.com/sub1/

Solution: RewriteCond %{HTTP_HOST} !^(www|ftp|mail).example.com RewriteCond %{HTTP_HOST} ^([^.]+).example.com RewriteRule (.*) /subd_%1/$1 [L]

Check your .htaccess file.

Your question was not that bad, just need to know what you used for serving.


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.