Home > PHP Framework > ThinkPHP > Summary of several routing forms of ThinkPHP

Summary of several routing forms of ThinkPHP

angryTom
Release: 2020-03-26 14:30:32
forward
3882 people have browsed it

本篇文章总结了ThinkPHP的几种路由形式,分别是普通模式、PATHINFO、REWRITE和兼容模式,希望对各位学习thinkphp的朋友有帮助!

Summary of several routing forms of ThinkPHP

thinkphp官方文档里有详细的说明:

ThinkPHP支持的URL模式有四种:普通模式、PATHINFO、REWRITE和兼容模式,

可以设置URL_MODEL参数改变URL模式。

(推荐教程:thinkphp教程

现在我们来总结一下这四种路由的格式:

1.普通路由(get形式路由)

htttp://localhost/?m=模块名(分组名)&c=控制器名&a=方法名&id=?
Copy after login

2.pathinfo路由形式(系统默认)

路由形式:http://网址/入口文件/模块名(分组名)/控制器名/方法/参数名/参数值

例如:http://localhost/index.php/home/user/login/var/value/

3.REWRITE模式

REWRITE模式是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地

址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。

如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:

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

接下来,就可以用下面的URL地址访问了: http://localhost/home/user/login/var/value

在后面的文章中,我会详细介绍。

4.兼容路由形式

兼容模式是用于不支持PATHINFO的特殊环境.

路由形式:http://网址/入口文件?s=/模块名(分组名)/控制器名/方法名/参数名/参数值

注意:这里的小s是兼容模式变量名称,是可以通过配置文件更改的。

The above is the detailed content of Summary of several routing forms of ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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