XAMPP仅可访问index.php无法打开其他网页求助
无法访问除index.php外的其他页面(XAMPP环境)
我在F:\磁盘安装了XAMPP,目前仅能访问index.php,其他网页都打不开。按照网上教程开启LoadModule rewrite_module modules/mod_rewrite.so(去掉#注释)后,能正常访问https://localhost/dashboard/,但加回#注释就会提示“Not found - the requested URL was not found on this server”。
环境信息
- Apache/2.4.58 (Win64)
- OpenSSL/3.1.3
- PHP/8.2.12
- 服务器地址:localhost,端口443
.htaccess加载验证
在.htaccess中添加无效内容(比如@@222hasdfjhasfd)时,会出现“Internal Server Error”,说明.htaccess已被正常加载执行。
当前Apache配置
DocumentRoot "F:/xampp/htdocs" <Directory "F:/xampp/htdocs"> Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews AllowOverride All Order allow,deny Allow from all </Directory>
当前.htaccess内容
DirectoryIndex index.php index.html <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php/ [L] </IfModule>
尝试访问其他网页时仍提示“file not found”错误,急需解决办法。
排查与解决步骤
修正RewriteRule路径问题
当前.htaccess最后一条规则末尾多了斜杠,会导致PHP接收请求路径异常,修改为:RewriteRule . /index.php [L]更新Apache 2.4访问控制语法
原配置使用的是Apache 2.2语法,2.4版本需替换为:<Directory "F:/xampp/htdocs"> Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews AllowOverride All Require all granted </Directory>关闭MultiViews选项
MultiViews可能干扰Rewrite规则,从Options中移除该选项:Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI确认文件物理存在性
访问的“其他网页”对应的物理文件必须存在于F:/xampp/htdocs目录下,文件名大小写尽量保持一致(Windows虽不区分,但避免潜在问题)。重启Apache服务
修改配置文件或.htaccess后,务必在XAMPP控制面板重启Apache,确保修改生效。
内容的提问来源于stack exchange,提问作者Peter Achutha
相关产品推荐
相关产品推荐

