有很多关于在wamp主页中更改哪些设置以显示虚拟主机列表的说明,但是在C://wamp/www中检查index.php时,似乎没有代码在这里显示虚拟主机,无论其他地方的设置是什么。所以,我自己添加了一些代码来显示这个列表,并认为它可能会帮助那些想要做同样的事情的人。
这要求您的httpd-vhosts.conf文件包含如下条目
<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>
现在,在C://wamp/www/index.php做以下修改:
在这行之后(第65行)$wampserverVersion = str_replace(' ',',$result[1]);
添加:
$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>n";;
然后滚动到文件的底部,编辑包含html的$pageContents。我决定不需要别名列表,所以注释掉这段代码:
<div class="third right">
<h2>{$langues[$langue]['txtAlias']}</h2>
<ul class="aliases">
${aliasContents}
</ul>
</div>
并替换为以下代码:
<div class="third right">
<h2>Your Virtual Hosts</h2>
<ul class="aliases">
${vHosts}
</ul>
</div>
如何打开WAMPServer2.5
我的虚拟主机菜单?
-
备份wampwampmanager。
-
编辑wampwampmanager.tpl
-
找到这个参数
;WAMPPROJECTSUBMENU
,它在[菜单]中。离开]"部分。 -
在
;WAMPPROJECTSUBMENU
参数之前或之后添加;WAMPVHOSTSUBMENU
。 -
现在左键点击 wampmanager图标,选择
Refresh
。 如果没有添加菜单,请退出并重启wampmanager。
注意新菜单只会出现,如果你已经有一些虚拟主机定义!否则,在定义一个或两个虚拟主机之前,您将看不到任何区别。
哦,如果是@Bollis正在阅读这篇文章,撤销您对index.php