如何实现ThinkPHP6.0 URL重写,去除Index.php?

更新于
2026-09-28 17:19:27
2阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计322个文字,预计阅读时间需要2分钟。

如何实现ThinkPHP6.0 URL重写,去除Index.php?

踩坑!官网给出的解决方案:解决重写URL,省去index.php问题。可以通过URL重写隐藏应用入口文件index.php,以下是相关服务器的配置参考:[Apache] httpd.conf配置文件中加载了mod_rewrite.so模块。

踩坑!

官网给的解决方案:解决重写URL,省去index.php问题

可以通过URL重写隐藏应用的入口文件index.php,下面是相关服务器的配置参考:

[ Apache ]
httpd.conf配置文件中加载了mod_rewrite.so模块
AllowOverride None 将None改为 All

把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] </IfModule>

官网文档中给的 .htaccess 文件内容如下

如何实现ThinkPHP6.0 URL重写,去除Index.php?

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #这一行踩坑 </IfModule>

正确的写法应该如下,官网给的最后一行配置错误

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] #这才是对的 </IfModule>

结尾

解决问题最好多看看官方给的文档,但有时候也不能全看官网文档,可以结合官网下面的讨论区,借鉴各个大佬们的回答去解决问题

本文共计322个文字,预计阅读时间需要2分钟。

如何实现ThinkPHP6.0 URL重写,去除Index.php?

踩坑!官网给出的解决方案:解决重写URL,省去index.php问题。可以通过URL重写隐藏应用入口文件index.php,以下是相关服务器的配置参考:[Apache] httpd.conf配置文件中加载了mod_rewrite.so模块。

踩坑!

官网给的解决方案:解决重写URL,省去index.php问题

可以通过URL重写隐藏应用的入口文件index.php,下面是相关服务器的配置参考:

[ Apache ]
httpd.conf配置文件中加载了mod_rewrite.so模块
AllowOverride None 将None改为 All

把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L] </IfModule>

官网文档中给的 .htaccess 文件内容如下

如何实现ThinkPHP6.0 URL重写,去除Index.php?

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] #这一行踩坑 </IfModule>

正确的写法应该如下,官网给的最后一行配置错误

<IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] #这才是对的 </IfModule>

结尾

解决问题最好多看看官方给的文档,但有时候也不能全看官网文档,可以结合官网下面的讨论区,借鉴各个大佬们的回答去解决问题