You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XAMPP VirtualHost配置异常:ssv2.localhost指向默认htdocs目录

问题描述

访问ssv2.localhost时,页面显示XAMPP默认的htdocs目录,期望将其指向htdocs\shopping_project\v2\files,同时让PHP的$_SERVER["DOCUMENT_ROOT"]设置为E:\xampp_8_1_6\htdocs\shopping_project\v2\files。已完成相关配置并重启XAMPP及系统,但问题仍存在。

当前配置信息

系统hosts文件内容

127.0.0.1 ssv2.localhost

Apache httpd-vhosts.conf配置

<VirtualHost *:80>
 ServerName localhost
 DocumentRoot "E:\xampp_8_1_6\htdocs"
 <Directory "E:\xampp_8_1_6\htdocs">
     DirectoryIndex index.php
 </Directory>
</VirtualHost>

<VirtualHost *:80>
     ServerAdmin original.smm1378@gmail.com
     ServerName ssv2.localhost
     DocumentRoot "E:\xampp_8_1_6\htdocs\shopping_project\v2\files"
     SetEnv APPLICATION_ENV "development"
     <Directory "E:\xampp_8_1_6\htdocs\shopping_project\v2\files">
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from all        
     </Directory>
 </VirtualHost>

httpd.conf相关配置

已确保Include conf/extra/httpd-vhosts.conf未被注释,且在文件末尾添加了以下内容:

<Directory />
    AllowOverride none
    Require all granted
</Directory>

问题排查与解决方案

  • 虚拟主机匹配顺序问题:Apache会按配置文件中虚拟主机的顺序匹配请求,第一个主机将作为默认主机。当前localhost的配置排在ssv2.localhost前面,可能导致请求被优先匹配到默认主机。解决方法:将ssv2.localhost的虚拟主机配置移到localhost配置的上方。
  • 权限规则版本冲突:Apache 2.4已使用Require all granted替代旧版的Order allow,deny+Allow from all,混用可能导致权限解析异常。同时httpd.conf末尾添加的根目录权限配置过于宽松,易引发冲突。解决方法:删除httpd.conf中新增的<Directory />配置,将虚拟主机内的目录权限替换为:
    <Directory "E:\xampp_8_1_6\htdocs\shopping_project\v2\files">
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
    
  • 浏览器缓存干扰:Firefox可能缓存了旧页面内容,导致新配置生效后仍显示默认目录。解决方法:按下Ctrl+Shift+R强制刷新页面,或清除浏览器缓存后重新访问。
  • 路径分隔符问题:Apache配置中建议使用正斜杠/作为路径分隔符,避免Windows反斜杠的转义问题。解决方法:将所有路径中的反斜杠替换为正斜杠,例如E:/xampp_8_1_6/htdocs/shopping_project/v2/files。

内容的提问来源于stack exchange,提问作者sajjad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 04:35:09