使用.htaccess隐藏URL中的index.php?p=无效,求解决方案
解决建议
先验证Apache基础配置
确保mod_rewrite模块已启用,同时目标目录(/ext)的Apache配置中AllowOverride设为All,否则.htaccess规则不会生效。修改httpd.conf中的对应目录配置:<Directory "/你的服务器实际路径/ext"> AllowOverride All Require all granted </Directory>保存后重启Apache服务。
替换
.htaccess规则
原规则仅实现了请求转发,未处理index.php?p=到路径的转换,替换为以下规则:<IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /ext/ # 重定向直接访问index.php的请求到目录根 RewriteRule ^index\.php$ /ext/ [R=301,L] # 将请求路径转为p参数传递给index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?p=$1 [L,QSA] # 禁用目录索引 Options All -Indexes </IfModule>调整tinyfilemanager配置
打开index.php,找到$base_url配置项,设置为你的子目录路径:$base_url = '/ext/';这一步确保工具生成的内部链接直接使用干净路径,而非带
index.php?p=的格式。
内容的提问来源于stack exchange,提问作者OHICT
相关产品推荐
相关产品推荐

