Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Configure the VHOSTS

Status
Not open for further replies.

seek4need

Technical User
Aug 12, 2008
14
US
Hi,

I am looking to configure the VHOSTS like below example:

Eg:

example.com
ex1.example.com
ex2.example.com


I try to configure the above example in httpd-vhosts.conf file. After configure when I given example.com or ex1.example.com the page is redirecting to example.com only. It is not pointing to ex1.example.com.

How I can configure to point to different pages for different aliases. If I given example.com it should go to that directory path. If I given ex1.example.com it should go to ex1 directory path.

Please check the below configuratoin parameters and please help me where I am doing wrong. hosts file is already taken care.



NameVirtualHost *:80
<VirtualHost example.com:80 >

#=================================================
#== VIRTUAL CONTAINER 1 < ==
#=================================================
NameVirtualhost ServerAdmin admin@example.com
#DocumentRoot /ServerName ServerAlias *.ServerSignature Email
ServerPath "C:/example.com/htdocs/"
DocumentRoot "C:/example.com/htdocs/"
<Directory />
HostnameLookups On
Options Indexes FollowSymLinks MultiViews
IndexOptions FancyIndexing
DirectoryIndex /index.html index.php
AllowOverride None
Order deny,allow
Allow from all
Satisfy All
</Directory>
ErrorLog "C:/example.com/logs/[www.example.com] error.log"
TransferLog "C:/example.com/logs/[www.example.com] access.log"
</VirtualHost>


#================================================= =========
#== VIRTUAL CONTAINER 2 < ==
#================================================= =========

<VirtualHost ex1.example.com:80>

NameVirtualhost ServerName ServerSignature Email
ServerAdmin admin@example.com
ServerPath "C:/example.com/htdocs/us/ex1/"
DocumentRoot "C:/example.com/htdocs/us/ex1/"
<Directory />
HostnameLookups On
Options Indexes FollowSymLinks MultiViews
IndexOptions FancyIndexing
DirectoryIndex /index.html index.php
AllowOverride None
Order deny,allow
Allow from all
Satisfy All
</Directory>
ErrorLog "C:/example.com/logs/[www.ex1.example.com] error.log"
TransferLog "C:/example.com/logs/[www.ex1.example.com] access.log"
</VirtualHost>


Thanks in Advance...!

Thanks,
Srinivas
 
First, take out the NameVirtualHost in each VirtualHost. This is a spec for the address to listen, not a name. Apache uses the ServerName or ServerAlias to match the names in the URL with the virutal host. It appears if you use it should work, but not ex1.example.com. You must add a ServerAlias to add ex1.example.com!
 
I did the changes as you said. But still it is redirecting to example.com domain. If I give ex1.example.com or example.com it is redirecting to example.com only.

Please see the below steps for changes I did....

step 1: I un commented the 2 places in httpd.conf file

# Fancy directory listings
Include conf/extra/httpd-autoindex.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Step2: I did the modification in the httpd-vhosts.conf file like below:

#NameVirtualHost *:80

<VirtualHost *:80>
ServerName #ServerAlias DocumentRoot "c:/example.com/htdocs"
</VirtualHost>


<VirtualHost *:80>
ServerName ServerAlias ex1.example.com
DocumentRoot "c:/example.com/htdocs/us/ex1"
</VirtualHost>


still it is redirecting to example.com only.
 
Hi,

Can any one have the solution for the above issue. I am still stuck at this point.

I am not able to point to the sub domain. it is always redirecting to main domain.

Thanks
 
I said the NameVirtualhost in EACH VirtualHost. Not the first one. You need that one.
 
Thank you so much Sir(elgrandeperro) It worked very well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top