本篇文章总结了ThinkPHP的几种路由形式,分别是普通模式、PATHINFO、REWRITE和兼容模式,希望对各位学习thinkphp的朋友有帮助!
thinkphp官方文档里有详细的说明:
ThinkPHP支持的URL模式有四种:普通模式、PATHINFO、REWRITE和兼容模式,
可以设置URL_MODEL参数改变URL模式。
(推荐教程:thinkphp教程)
现在我们来总结一下这四种路由的格式:
1.普通路由(get形式路由)
htttp://localhost/?m=模块名(分组名)&c=控制器名&a=方法名&id=?
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>
接下来,就可以用下面的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!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)