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

XAMPP本地域名不读取.htaccess,无法重定向至index.php求助

本地XAMPP环境下.htaccess不生效的解决办法

核心问题

你的VirtualHost配置中,DocumentRoot指向了项目根目录,但index.php和.htaccess实际存放在(root)/public目录下,同时Apache默认可能未启用.htaccess的解析权限,导致访问域名时直接暴露根目录文件,未触发重定向。

解决步骤

1. 修正VirtualHost的DocumentRoot路径

将VirtualHost配置中的DocumentRoot修改为指向public子目录,同时添加目录权限配置确保.htaccess生效:

<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs\ARCADIA-2025-LASTRUN\public"
    ServerName ARCADIA-2025-LASTRUN.local

    <Directory "C:\xampp\htdocs\ARCADIA-2025-LASTRUN\public">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

2. 修复.htaccess的语法错误

你的.htaccess中RewriteCond规则缺少空格,Apache本地环境对语法要求更严格,需修正为:

RewriteEngine On

# 允许加载实际存在的文件和目录
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# 将其他所有请求转发到index.php
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

3. 重启Apache服务

修改配置后,打开XAMPP控制面板重启Apache服务,确保新配置生效。

验证方法

访问ARCADIA-2025-LASTRUN.local,此时应自动转发到index.php,不再暴露项目根目录的文件列表。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:54:54