通常状况下,每一个项目占用一个根目录,而不是一个根目录下面有多个项目。php
好比说,安装xampp,xampp的安装路径为:D:\apache
安装好后,D盘下面就会有一个文件夹:xampp,如图:ide
而默认的xampp的根目录是xampp文件夹下的htdocs文件夹,即根目录的路径为:spa
D:\xampp\htdocs\code
若是htdocs文件夹下有一个文件,叫作index.php,咱们就能够这样访问:class
localhost/index.phpList
这就等价于搜索
D:\xampp\htdocs\index.php。请求
若是咱们有2个项目,一个叫a项目,一个叫b项目,如图:方法
若是咱们想分别访问,就必须这样写:
localhost/a/index.php
localhost/b/index.php
这就是所谓的单一的根目录。那咱们能不能为a和b项目各设置一个根目录呢?这样咱们访问a和b项目时就能够这样访问:
localhost/index.php (即localhost/a/index.php)
localhost:8090/index.php (即localhost/b/index.php)
这样,a的根目录就是localhost,b的根目录就是localhost:8090
这里,localhost的路径就是D:\xampp\htdocs\a\,localhost:8090的路径是D:\xampp\htdocs\b\。
方法:
①
点击Config,并打开Apache(httpd.conf)文件
②
搜索Listen字,在Listen 80下添加一句:Listen 0.0.0.0:8090
意思是再监听一个端口,这个端口是8090
③再在这个文件中搜索:directory,找到如图所示
这句是拒绝全部请求,删掉这一句,改为 :Allow from all ,如图
意思是,容许全部。
而后把AllowOverride none改为AllowOverride all,即全部都重定向
④在D:\xampp\apache\conf\extra中找到httpd-vhosts.conf文件,并打开
⑤在文件的最下面添加以下语句:
<VirtualHost *:8090> ServerName localhost DocumentRoot D:/xampp/htdocs/b </VirtualHost>
上面的DocumentRoot就能够设置根目录的路径了,咱们想要把b项目做为根目录,因此路径写到b文件夹。此时访问b项目下的index.php时就能够直接写:
localhost:8090/index.php
同理,a项目也能够设置,只要设置不一样的端口号就行啦。