thinkphp5去除index.php的几大方式,根治各种不行

Posted ming

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thinkphp5去除index.php的几大方式,根治各种不行相关的知识,希望对你有一定的参考价值。

在tp5中官方给出的去隐藏index.php方法如下:

 

[ Apache ]

  1. httpd.conf配置文件中加载了mod_rewrite.so模块
  2. AllowOverride None 将None改为 All
  3. 把下面的内容保存为.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>
    

[ nginx ]

在Nginx低版本中,是不支持PATHINFO的,但是可以通过在Nginx.conf中配置转发规则实现:

location / { // …..省略部分代码
   if (!-e $request_filename) {
   		rewrite  ^(.*)$  /index.php?s=/$1  last;
    }
}

  

本人本地环境如下:phpstudy2018。官方给出的方法在一些集中的PHP环境中应该是可用的(本人没测过)。

今天本人配了一thinkadmin,折腾许久去不掉index.php。

改进方法有如下几种:

1、在index.php后面加个问号。如果从url地扯上理解,应该是问号后面算是参数(tp实现MVC原理就根据这个了),我写过dede二开,也是传不同参数调用不同方法。

RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

 

2、用tp  phpinfo兼容模式,即加了s

RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]

 

3、加上PHPINFO参数

RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] 


————————————————
版权声明:本文为CSDN博主「陆平平」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011383596/article/details/80663471

 

 

另一博主文章:

 

 

public文件夹下,有个.htacess文件,没有则新建一个, 如果已有这个文件,原文件内容如下:

<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>


如果此时还是报错 : “No input file specified.”;

 

那么就重写规则把最后一行

RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 

改为

RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L] 

即可!

以上是关于thinkphp5去除index.php的几大方式,根治各种不行的主要内容,如果未能解决你的问题,请参考以下文章

Yii优化路由Apache配置(在APACHE服务器上的访问方式上去除index.php)

[转]ThinkPHP5 隐藏index.php问题

thinkphp5.1隐藏index.php入口文件

thinkphp5.0如何隐藏index.php入口文件

nginx thinkphp5 多入口配置

thinkphp5, 省略index.php