当前位置:网站首页>详解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
边栏推荐
- Realize a simple version of array by yourself from
- Simple implementation of call, bind and apply
- sql-lab (54-65)
- 【统计学习方法】学习笔记——第五章:决策树
- Processing strategy of message queue message loss and repeated message sending
- SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels
- 【统计学习方法】学习笔记——第四章:朴素贝叶斯法
- Importance of database security
- leetcode刷题:二叉树19(合并二叉树)
- About IPSec
猜你喜欢
SQL Lab (41~45) (continuous update later)
Processing strategy of message queue message loss and repeated message sending
About web content security policy directive some test cases specified through meta elements
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
[statistical learning method] learning notes - support vector machine (Part 2)
The left-hand side of an assignment expression may not be an optional property access.ts(2779)
Polymorphism, final, etc
visual stdio 2017关于opencv4.1的环境配置
About sqli lab less-15 using or instead of and parsing
随机推荐
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
About IPSec
SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
PHP调用纯真IP数据库返回具体地址
[deep learning] image multi label classification task, Baidu paddleclas
Static comprehensive experiment
[statistical learning method] learning notes - logistic regression and maximum entropy model
Realize all, race, allsettled and any of the simple version of promise by yourself
Vxlan 静态集中网关
How to apply @transactional transaction annotation to perfection?
【二叉树】删点成林
SQL Lab (41~45) (continuous update later)
Master formula. (used to calculate the time complexity of recursion.)
MPLS experiment
利用棧來實現二進制轉化為十進制
2022-07-07日报:GAN发明者Ian Goodfellow正式加入DeepMind
SQL Lab (46~53) (continuous update later) order by injection
ip2long与long2IP 分析
gcc 编译报错
leetcode刷题:二叉树23(二叉搜索树中的众数)