There are plenty of instruction on what settings to change to show the Virtual Hosts list in the wamp homepage, however upon inspecting index.php in C://wamp/www there appeared to be no code in here to show the Virtual Hosts no matter what the settings were elsewhere. So, I have added some code in myself to show this list and thought it might help others who want to do the same.
This requires your httpd-vhosts.conf file to have entries such as the following
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/website_folder_name"
ServerName Website_Name #<----------This is the what index.php uses
<Directory "C:/wamp/www/website_folder_name">
AllowOverride All
Require local
</Directory>
</VirtualHost>
Now, in C://wamp/www/index.php make the following changes:
After this line (line 65) $wampserverVersion = str_replace('"','',$result[1]);
Add:
$wampVHostsFile = $server_dir.'bin/apache/apache2.4.9/conf/extra/httpd-vhosts.conf';
if (!is_file($wampVHostsFile))
die ('Unable to open Virtual Hosts file, please change path in index.php file');
$fp = fopen($wampVHostsFile,'r');
$wampVHostsFileContents = fread ($fp, filesize ($wampVHostsFile));
fclose ($fp);
$vHosts = "";
$result = array(1=>array(1=>786));
while(! empty($result)) {
preg_match('|ServerName (.*)|',$wampVHostsFileContents,$result, PREG_OFFSET_CAPTURE, $result[1][1]);
array_key_exists(1, $result) ? $vHosts .= '<li><a href="'.($suppress_localhost ? 'http://' : '').$result[1][0].'">'.$result[1][0].'</a></li>' : null;
}
if (empty($vHosts))
$vHosts = "<li>No Virtual Hosts</li>
";;
Then scroll to the bottom of the file and edit $pageContents containing the html. I decided I didn't want the list of aliases so comment out this code:
<div class="third right">
<h2>{$langues[$langue]['txtAlias']}</h2>
<ul class="aliases">
${aliasContents}
</ul>
</div>
And replace with this code:
<div class="third right">
<h2>Your Virtual Hosts</h2>
<ul class="aliases">
${vHosts}
</ul>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…