Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

UPDATE 1:

I now have the following:

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

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

Which does not work when I type into the browser

http://test.companyname.com

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  ]

ORIGINAL QUESTION:

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.

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

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>

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

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.

share|improve this answer
    
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
add comment

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.

share|improve this answer
    
this should prove helpful for you as well... httpd.apache.org/docs/2.0/misc/rewriteguide.html –  Seth Apr 4 '11 at 16:19
    
Please see update 1 in original question. –  oshirowanen Apr 5 '11 at 9:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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