当前位置:网站首页>详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
2022-07-07 10:37:00 【全栈程序员站长】
URL模式 URL_MODEL设置 普通模式
0 PATHINFO模式 1 REWRITE模式 2 兼容模式 3
如果你整个应用下面的模块都是采用统一的URL模式,就可以在应用配置文件中设置URL模式,如果不同的模块需要设置不同的URL模式,则可以在模块配置文件中设置。
普通模式
普通模式也就是传统的GET传参方式来指定当前访问的模块和操作,例如: http://localhost/?m=home&c=user&a=login&var=value m参数表示模块,c参数表示控制器,a参数表示操作(当然这些参数都是可以配置的),后面的表示其他GET参数。 如果默认的变量设置和你的应用变量有冲突的话,你需要重新设置系统配置,例如改成下面的:
‘VAR_MODULE’ => ‘module’, // 默认模块获取变量 ‘VAR_CONTROLLER’ => ‘controller’, // 默认控制器获取变量 ‘VAR_ACTION’ => ‘action’, // 默认操作获取变量
上面的访问地址则变成: http://localhost/?module=home&controller=user&action=login&var=value
注意,VAR_MODULE只能在应用配置文件中设置,其他参数可以则也可以在模块配置中设置
PATHINFO模式
PATHINFO模式是系统的默认URL模式,提供了最好的SEO支持,系统内部已经做了环境的兼容处理,所以能够支持大多数的主机环境。对应上面的URL模式,PATHINFO模式下面的URL访问地址是: http://localhost/index.php/home/user/login/var/value/ PATHINFO地址的前三个参数分别表示模块/控制器/操作。 不过,PATHINFO模式下面,依然可以采用普通URL模式的参数方式,例如: http://localhost/index.php/home/user/login?var=value 依然是有效的 PATHINFO模式下面,URL是可定制的,例如,通过下面的配置:
// 更改PATHINFO参数分隔符
‘URL_PATHINFO_DEPR’=>’-‘,
我们还可以支持下面的URL访问: http://localhost/index.php/home-user-login-var-value REWRITE模式
REWRITE模式是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。 如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php/1 [QSA,PT,L]
接下来,就可以用下面的URL地址访问了: http://localhost/home/user/login/var/value
更多环境的URL重写支持参考部署部分的URL重写。
兼容模式
兼容模式是用于不支持PATHINFO的特殊环境,URL地址是: http://localhost/?s=/home/user/login/var/value 可以更改兼容模式变量的名称定义,例如:
‘VAR_PATHINFO’ => ‘pathinfo’
PATHINFO参数分隔符对兼容模式依然有效,例如:
// 更改PATHINFO参数分隔符
‘URL_PATHINFO_DEPR’=>’-‘,
使用以上配置的话,URL访问地址可以变成: http://localhost/?s=/home-user-login-var-value 兼容模式配合Web服务器重写规则的定义,可以达到和REWRITE模式一样的URL效果。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113484.html原文链接:https://javaforall.cn
边栏推荐
- Multi row and multi column flex layout
- SQL Lab (41~45) (continuous update later)
- Day-17 connection set
- leetcode刷题:二叉树21(验证二叉搜索树)
- [Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
- Attack and defense world ----- summary of web knowledge points
- SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
- SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
- idm服务器响应显示您没有权限下载解决教程
- Day-19 IO stream
猜你喜欢

ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics

SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)

Financial data acquisition (III) when a crawler encounters a web page that needs to scroll with the mouse wheel to refresh the data (nanny level tutorial)
![[pytorch practice] use pytorch to realize image style migration based on neural network](/img/20/8ed7113115709b6169be289b0c280a.png)
[pytorch practice] use pytorch to realize image style migration based on neural network

SQL Lab (41~45) (continuous update later)

About IPSec

How to apply @transactional transaction annotation to perfection?

AirServer自动接收多画面投屏或者跨设备投屏

图形对象的创建与赋值
![[statistical learning method] learning notes - logistic regression and maximum entropy model](/img/f7/857d053cc2cee81c24919aafab3c6e.png)
[statistical learning method] learning notes - logistic regression and maximum entropy model
随机推荐
[pytorch practice] image description -- let neural network read pictures and tell stories
The road to success in R & D efficiency of 1000 person Internet companies
【PyTorch实战】用RNN写诗
[deep learning] image multi label classification task, Baidu paddleclas
BGP actual network configuration
【统计学习方法】学习笔记——第四章:朴素贝叶斯法
Static routing assignment of network reachable and telent connections
SQL head injection -- injection principle and essence
Master formula. (used to calculate the time complexity of recursion.)
@Resource和@Autowired的区别?
leetcode刷题:二叉树24(二叉树的最近公共祖先)
leetcode刷题:二叉树19(合并二叉树)
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
什么是ESP/MSR 分区,如何建立ESP/MSR 分区
[learn wechat from 0] [00] Course Overview
[statistical learning methods] learning notes - Chapter 5: Decision Tree
Object. Simple implementation of assign()
Day-19 IO stream
图形对象的创建与赋值
How much does it cost to develop a small program mall?