Home >PHP Framework >ThinkPHP >Several ways to remove index.php in thinkphp5

Several ways to remove index.php in thinkphp5

藏色散人
藏色散人Original
2020-08-15 10:24:393357browse

thinkphp去除index.php的实现方法:首先打开“httpd.conf”文件;然后将“AllowOverride None”将None改为“All”;最后将htaccess文件放到应用入口文件的同级目录下即可。

Several ways to remove index.php in thinkphp5

推荐:《thinkphp教程

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

[ Apache ]

  1. httpd.conf配置文件中加载了mod_rewrite.so模块
  2. AllowOverride None 将None改为 All
  3. 把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下
accc8b222b481b6a3bae338f95f68faf
  Options +FollowSymlinks -Multiviews  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d  RewriteCond %{REQUEST_FILENAME} !-f  RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]2071f931c9870be1bebed0bdda8305e7

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

The above is the detailed content of Several ways to remove index.php in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn