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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 virtual hosts 1 documentroot problem 4

Status
Not open for further replies.

piti

Technical User
Apr 12, 2001
627
SK
I have 2 virtual hosts configured on my apache and need this to be done:

when accessing the server opens index1.php
and when accessing the server opens index2.php

index1.php and index2.php are in the same directory
both servers are using the same scripts, only the first page opened is diferent(setting specific parameters)

is there any possibility how to do this or do i need to copy everything in a special directory and set that as document root for the other server?
 
i'd have two separate dirs for each root dir, and then symlink the rest of the stuff in you rootdir.
you are using a proper operating system right?
 
You could also do the following in your httpd.conf file:
This will set up 2 Virtual Hosts, utilizing the DirectoryIndex directive to call the right "index" page based on the server :)

This is based on something I had to do for a customer that was quite similar to your situation, and it works like a charm :)

<VirtualHost ServerAdmin admin@server1.tld
NameVirtualHost <IP ADDRESS #1>
ServerName DocumentRoot /home/httpd/html
ErrorLog /home/httpd/error_log
ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/
Options ExecCGI Includes Indexes FollowSymlinks
DirectoryIndex index1.php index.php index.html index.php3 index.shtml
CustomLog /home/httpd/access_log combined
ServerAlias server1.tld
</VirtualHost>

<VirtualHost ServerAdmin admin@server2.tld
NameVirtualHost <IP ADDRESS #2>
ServerName DocumentRoot /home/httpd/html
ErrorLog /home/httpd/error_log2
ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/
Options ExecCGI Includes Indexes FollowSymlinks
DirectoryIndex index2.php index.php index.html index.php3 index.shtml
CustomLog /home/httpd/access_log2 combined
ServerAlias server2.tld
</VirtualHost>
 
thanks guys

btw i'm a newbie to apache so MrTom could you explain me that symlinks
with proper os you mean unix/linux type i think, if so i'm running on mandrake
 
johns reply is much better than mine :)

but if you want to know about symlinks

echo &quot;hello&quot; > test.html
ln -s test.html link.html
ls -l

you'll see that the file &quot;link.html&quot; has an arrow to &quot;test.html&quot;. if you look at link.html using &quot;cat link.html&quot; you'll see it IS test.html. if you edit test.html then link.html will change.

the &quot;ln -s&quot; means create a symlink.

use johns solution tho :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top