thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation (15) _php Tutorial

Source: Internet
Author: User

thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation (15)


This section: Details thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation

First, URL rules
1, the default is case-sensitive
2, if we do not want to distinguish between the case can change the configuration file
' url_case_insensitive ' =>true,//url case insensitive
* Module name is too long for the case:
A, if the module is named Usergroupaction, complex module (usually indexaction)
Then the URL to find the module is necessary to write
Http://localhost/thinkphp4/index.php/user_group/index
B, if ' url_case_insensitive ' =>false (case-sensitive condition can be accessed)
Then the URL can also be written as
Http://localhost/thinkphp4/index.php/UserGroup/index


Second, URL pseudo-static (TP default support pseudo-static)
Http://localhost/thinkphp4/index.php/UserGroup/index.xml
* Default PDO, HTML, XML ... is supported, if you want to limit the configuration.
' Url_html_suffix ' = ' html|shtml|xml ',//limit pseudo-static suffix


Third, URL routing
1. Start the route
To turn on routing support in the configuration file
' url_router_on ' = = true,//Turn on routing
2. Using routing
1. Rule Expressions Configure Routing
' url_router_on ' = = true,//Turn on routing
' Url_route_rules ' = Array (
' My ' = ' index/index ',//static address routing access: Http://localhost/thinkphp/index.php/my
': Id/:num ' + ' index/index ', */* After the numeric value of random write, the letter will be OK
Dynamic Address Routing access: http://localhost/thinkphp/index.php/10/200
You can pass a value or get it in the module controller using get
echo $_get[' id '];
echo $_get[' num '];
*/
' My/:num ' = ' index/index ',//mixed address routing http://localhost/thinkphp/index.php/my/200
' year/:year/:month/:d ate ' = ' index/index ',//dynamic and static mixed address routing: HTTP://LOCALHOST/THINKPHP/INDEX.PHP/YEAR/2014/12/21
' year/:year\d/:month\d/:d ate\d ' = ' index/index ',//dynamic and static mixed address routing--plus \d representative type can only be numeric
' my/:id$ ' = ' index/index ',//plus $ Description The address can only be my/1000 there's nothing else left behind.
);


2. Regular expression Configuration routing
Http://localhost/thinkphp/index.php/year/2014/12/21
'/^year\/(\d{4}) \ (\d{2})/(\d{2})/' = ' index/index?year=:1&month=:2&date=:3 '


3. Precautions:
1. The more complex the route the more forward
' Url_route_rules ' =>array (
' my/:year/:month:/:d ay ' = ' index/day ', * Complex routes are placed in front of them and will not be executed at the back
' my/:id\d ' = ' index/index ',
' My/:name ' = ' index/index ',
)
2. You can use the route rule as an exact match (no matter the complex no, it will match all the regular)
' Url_route_rules ' =>array (
' my/:id\d$ ' = ' index/index ',
' my/:name$ ' = ' index/index ',
' my/:year/:month:/:d ay$ ' = ' index/day ',
),
3. Using regular matching methods
' 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 ',
),


iv. URL Rewriting
For example: http://localhost/thinkphp/index.php/Index/index.html/t/my----don't want index.php to show up.
The following is the Apache configuration process, you can refer to the following:
1. The mod_rewrite.so module is loaded in the httpd.conf configuration file
2. AllowOverride None Change None to all
3. Make sure Url_model is set to 2 (this step is omitted)
4. Save the following content as a. htaccess file in a sibling directory of the portal file

Rewriteengine on
Rewritecond%{request_filename}!-d
Rewritecond%{request_filename}!-f
Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]

After restarting Apache, the original
You can access it by accessing
http://localhost/thinkphp/Index/index.html/t/my-simplified URL address, SEO support is better


v. URL generation(The manual is described in detail)
Public Function URL () {
echo U (' Index/add '); The URL address of the add operation that generated the index module
Thinkphp/index.php/index/add
}

Previous article http://qdxinbj8.2cto.com/index.php?m=content&c=content&a=public_preview&steps=1&catid=75 &id=363637

http://www.bkjia.com/PHPjc/934466.html www.bkjia.com true http://www.bkjia.com/PHPjc/934466.html techarticle thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation (15) This section: Details about thinkphp URL rules, url pseudo-static, url routing, url rewriting, url generation 、...

  • Related Article

    E-Commerce Solutions

    Leverage the same tools powering the Alibaba Ecosystem

    Learn more >

    Apsara Conference 2019

    The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

    Learn more >

    Alibaba Cloud Free Trial

    Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

    Learn more >

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.