thinkphp的URL路由规则与配置实例,thinkphpurl
本文实例讲述了thinkphp的URL路由规则与配置方法。分享给大家供大家参考。具体分析如下:
一、URL规则
1、默认是区分大小写的
2、如果我们不想区分大小写可以改配置文件
复制代码 代码如下:
'URL_CASE_INSENSITIVE'=>true,//url不区分大小写
3、如果模块名为 UserGroupAction,那么url找模块就必要要写成
复制代码 代码如下:
http://localhost/thinkphp4/index.php/user_group/index
4、如果'URL_CASE_INSENSITIVE'=>false,那么url也可以写为
复制代码 代码如下:
http://localhost/thinkphp4/index.php/UserGroup/index
二、URL伪静态
复制代码 代码如下:
'URL_HTML_SUFFIX'=>'html|shtml|xml',//限制伪静态的后缀
三、URL路由
1、启动路由
要在配置文件中开启路由支持
复制代码 代码如下:
'URL_ROUTER_ON'=>ture//开启路由
2、使用路由
1.规则表达式配置路由
复制代码 代码如下:
'URL_ROUTE_RULES'=>array()//路由规则
'my'=>'Index/index',//静态地址路由
'my'=>'/Index/index',//静态地址路由,加/直接跳到网站根目录下。
':id/:num'=>'Index/index',//动态地址路由,可以$_GET接收地址栏参数
'year/:year/:month/:date'=>'Index/index',//动态和静态混合地址路由
'year/:year\d/:month\d/:date\d'=>'Index/index',//动态和静态混合地址路由加上 \d代表类型只能是数字
'my/:id$'=>'Index/index',// 加上$说明地址中只能是 my/1000 后面不能有其他内容了
2.正则表达式配置路由,必须以/开始 /结束
复制代码 代码如下:
'/^year\/(\d{4})\/(\d{2})\/(\d{2})/'=>'Index/index?year=:1&month=:2&date=:3'//这里\d表示必须是数字
3、注意事项:
1.越复杂的路由越往前面放
复制代码 代码如下:
'URL_ROUTE_RULES'=>array(
'my/:year/:month:/:day'=>'Index/day',
'my/:id\d'=>'Index/index',
'my/:name'=>'Index/index',
)
2.可以使用$作为完全匹配的路由规则
复制代码 代码如下:
'URL_ROUTE_RULES'=>array(
'my/:id\d$'=>'Index/index',
'my/:name$'=>'Index/index',
'my/:year/:month:/:day$'=>'Index/day',
),
3.用正则匹配的方式,以/^开始,以$/结束
复制代码 代码如下:
'URL_ROUTE_RULES'=>array(
'/^my\/(\d+)$/'=>'Index/index?id=:1',
'/^my\/(\w+)$/'=>'Index/index?name=:1',
'/^my\/(\d{4})\/(\d{2})\/(\d{2})$/'=>'Index/day?year=:1&month=:2&day=:3',
),
希望本文所述对大家的ThinkPHP建站有所帮助。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

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