views:

53

answers:

2

I've to domain names pointing to the same IP.

What I want to do is:

When visited by domain_name1,make document_root:/usr/local/apache/htdocs1

when visited by domain_name2,make document_root:/usr/local/apache/htdocs2

how to do this job?

+1  A: 

(Note: this question should really go on ServerFault)

What you want to achieve is known as name-based virtual hosting.

Example of this from the referenced page:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
andri
what if the user just visit by 'domain1.com'?
Shore
Just add another <VirtualHost> entry for domain1.com, or use the ServerAlias directive to specify all the possible aliases in one VirtualHost entry. See the first example virtual host for details on that.
andri
cool guy! ..:)
Shore
strange,after adding this,it starts to report 403 forbidden?
Shore
Check the Apache error log for any details on what might be wrong (although you may want to first check first if the web server user has access to the directory set as DocumentRoot as any configuration errors should cause a 500 error instead)
andri
A: 

Using Virtual Hosts (samples)

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.domain1.com
    DocumentRoot /usr/local/apache/htdocs1
</VirtualHost>
<VirtualHost *:80>
    ServerName www.domain2.com
    DocumentRoot /usr/local/apache/htdocs2
</VirtualHost>
Vinko Vrsalovic
it seems you hard coded www into servername,what if the user just visit by 'domain1.com'?
Shore