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

Several ways to remove index.php in thinkphp5

藏色散人
Release: 2020-08-15 10:24:39
Original
3358 people have browsed it

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文件放到应用入口文件的同级目录下
<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>
Copy after login

[ Nginx ]

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

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

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

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

改进方法有如下几种:

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

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

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

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

3、加上PHPINFO参数

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template