Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set url mode for php

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to set the url mode for php. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The method of setting url mode by php: 1, setting whether url is case-sensitive by "URL_CASE_INSENSITIVE'= > true"; 2, limiting pseudo-static suffixes by "'URL_HTML_SUFFIX'= >' html | shtml | xml'"; 3, setting URL routing.

This article operating environment: windows7 system, PHP7.1 version, Dell G3 computer.

How does php set url mode?

PHP sets URL

I. URL rules

1. The default is case-sensitive

2. If we do not want to be case sensitive, we can change the configuration file.

'URL_CASE_INSENSITIVE'= > true, / / url is case-insensitive

3. If the module is named UserGroupAction

Then the url search module needs to be written as

Http://localhost/thinkphp4/index.php/user_group/index

4. If 'URL_CASE_INSENSITIVE'= > false

Then url can also be written as

Http://localhost/thinkphp4/index.php/UserGroup/index

2. URL pseudo-static

'URL_HTML_SUFFIX'= >' html | shtml | xml',// restricts pseudo-static suffixes

III. URL routing

1. Start routing

To enable routing support in the configuration file

2. Use routing

1. Rule expressions configure routing

'my'= >' Index/index',// static address routing': id/:num'= > 'Index/index',// dynamic address routing' year/:year/:month/:date'= > 'Index/index',// mixed address routing' year/:year\ d/:month\ d/:date\ static routing = > 'Index/index',// dynamic and static mixed address routing

Plus\ d means that the type can only be a number

'my/:id$'= >' Index/index',// plus $indicates that there can only be my/1000 in the address and nothing else can be added.

two。 Regular expressions configure routing

'/ ^ year\ / (\ d {4})\ / (\ d {2})\ / (\ d {2}) /' = > 'Index/index?year=:1&month=:2&date=:3'

3. Points for attention:

1. The more complex the route, the more forward it is.

'URL_ROUTE_RULES'= > array (' my/:year/:month:/:day'= > 'Index/day',' my/:id\ Index/index', = > 'Index/index',' my/:name'= > 'Index/index',)

two。 You can use $as an exact match for the routing rule

'URL_ROUTE_RULES'= > array (' my/:id\ dcards = > 'Index/index',' my/:name$'= > 'Index/index',' my/:year/:month:/:day$'= > 'Index/day',)

3. In the way of regular matching

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

Four: URL rewriting

(1): enable rewrite under Apache--- > httpd.conf:

# LoadModule rewrite_module modules/mod_rewrite.so can remove #

(2): AllowOverride None changes None to All: that is

AllowOverride None Options None Require all granted

(3): make sure URL_MODEL is set to 2 (no need to modify)

(4): save the following as a .htaccess file and put it in the same level directory of the entry file

RewriteEngine on RewriteCond% {REQUEST_FILENAME}!-d RewriteCond% {REQUEST_FILENAME}!-f RewriteRule ^ (. *) $index.php/$1 [QSA,PT,L]

Then restart Apache

On how to set php url mode to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report