thinkphp中URL_MODEL设置为2后,U方法解析出来的地址还是有Index.php

2025年03月24日 07:55
有1个网友回答
网友(1):

1、新建 .htaccess 文件于index.php同级目录 (win系统下可以用记事本另存为保存文件名.htaccess,另存时选择所有文件);

2、打开新建的.htaccess文件,
写入以下正则:


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] //①
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] //②

说明:①或者②只需要写一个即可,一个不行换另一个。(#为注释符号);

3、看服务器配置
如果是Apache服务器按下列操作:

查找Ctrl+F输入 rewrite_module 去掉注释符号

查找 AllowOverride 把之后所有的 None 改为 All
保存重启

4、OK!