Home Backend Development PHP Tutorial ThinkPHP URL守则、URL伪静态、URL路由

ThinkPHP URL守则、URL伪静态、URL路由

Jun 13, 2016 pm 12:46 PM
gt index url year

ThinkPHP URL规则、URL伪静态、URL路由

ThinkPHP 3.1.2?URL规则、URL伪静态、URL路由

一、URL规则

1、URL默认是区分大小写的

2、如果我们不想区分大小写可以改配置文件

'URL_CASE_INSENSITIVE'=>true,//值为true是说明url不区分大小写

3、如果模块名为 UserGroupAction

那么url找模块就必要要写成

http://localhost/thinkphp/index.php/user_group/index

4、如果'URL_CASE_INSENSITIVE'=>false ? //区分大小写

那么url也可以写为

http://localhost/thinkphp/index.php/UserGroup/index

二、URL伪静态

'URL_HTML_SUFFIX'=>'html|shtml|xml',//限制伪静态的后缀

三、URL路由

1、启动路由

要在配置文件中开启路由支持

? ? ? ? ? ? ? ? 'URL_ROUTER_ON'=>true,

? ? ? ? ? ? ? ? 并配置'URL_ROUTE_RULES'参数

?

2、使用路由

1.规则表达式配置路由

'my'=>'Index/index',//静态地址路由

':id/:num'=>'Index/index',//动态地址路由

'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'

3、注意事项:

1.越复杂的路由越往前面放,否则造成url解析混乱

'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',

),

?

?

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What file is index.html? What file is index.html? Feb 19, 2024 pm 01:36 PM

index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: &lt

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

PHP function introduction—get_headers(): Get the response header information of the URL PHP function introduction—get_headers(): Get the response header information of the URL Jul 25, 2023 am 09:05 AM

PHP function introduction—get_headers(): Overview of obtaining the response header information of the URL: In PHP development, we often need to obtain the response header information of the web page or remote resource. The PHP function get_headers() can easily obtain the response header information of the target URL and return it in the form of an array. This article will introduce the usage of get_headers() function and provide some related code examples. Usage of get_headers() function: get_header

Why NameResolutionError(self.host, self, e) from e and how to solve it Why NameResolutionError(self.host, self, e) from e and how to solve it Mar 01, 2024 pm 01:20 PM

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

What is the difference between html and url What is the difference between html and url Mar 06, 2024 pm 03:06 PM

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

How to get your Steam ID in a few steps? How to get your Steam ID in a few steps? May 08, 2023 pm 11:43 PM

Nowadays, many Windows users who love games have entered the Steam client and can search, download and play any good games. However, many users' profiles may have the exact same name, making it difficult to find a profile or even link a Steam profile to other third-party accounts or join Steam forums to share content. The profile is assigned a unique 17-digit id, which remains the same and cannot be changed by the user at any time, whereas the username or custom URL can. Regardless, some users don't know their Steamid, and it's important to know this. If you don't know how to find your account's Steamid, don't panic. In this article

How to use URL encoding and decoding in Java How to use URL encoding and decoding in Java May 08, 2023 pm 05:46 PM

Use url to encode and decode the class java.net.URLDecoder.decode(url, decoding format) decoder.decoding method for encoding and decoding. Convert into an ordinary string, URLEncoder.decode(url, encoding format) turns the ordinary string into a string in the specified format packagecom.zixue.springbootmybatis.test;importjava.io.UnsupportedEncodingException;importjava.net.URLDecoder;importjava.net. URLEncoder

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

See all articles