In doing thinkphp development projects, met a demand: Let requirements linked sites must end with .html.
The reason: In thinkphp project development, the use of pseudo-static routing format: xxx.com/xxx/2.html, but the latter is the default .html, can also be accessed by visiting xxx.com/xxx/2.
Now requires only be through: xxx.com/xxx/2.html access, that is, the end must have .html
Solution:
1, or the server apache nginx is configured to redirect.
2, to solve the routing through thinkphp
We can be performed by a method of verifying whether the current route with .html.
To do:
Step 1: Configure routing
':name/:id' => ['index/index/details',['before_behavior'=>'\app\index\behavior\UserCheck']],
Step Two: Custom method was validated
<?php namespace app\index\behavior; class UserCheck{ public function run(){ $url = request()->url(); if(!preg_match("/[\w\d]*.html$/",$url)){ echo "不是以.html结尾的URL"; // header("HTTP/1.1 404 Not Found");exit; } } }