thinkphp 路由不支持.(点)的问题

tp版本:3.2.1 配置路由的时候碰到的问题,如下:

'URL_ROUTE_RULES' => array(
    '/^new/(d+)$/'            => 'News/read?id=:1',
    '/^new/(w+)$/'            => 'News/read?name=:1'
)

配置后访问没有问题,默认情况下 以任何后缀访问都能正常访问该页面,例如:

  http://t.com/home/new/1

  http://t.com/home/new/1.ps

  http://t.com/home/new/1.xxx

  http://t.com/home/new/1.ii

但是想配置成只能是.html或规定的几种格式结尾,其他后缀不想让支持 于是配置如下:

'URL_ROUTE_RULES' => array(
    '/^new/(d+).html$/'            => 'News/read?id=:1',
    '/^new/(w+).html$/'            => 'News/read?name=:1'
)

这时候就访问不了,文档说明

试过了还是不行

最后修改Route.class.php  58行左右

if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { // 正则路由

修改成

$subject = sprintf("%s.%s", $regx, __EXT__);
if(0===strpos($rule,'/') && preg_match($rule,$subject,$matches)) { // 正则路由

终于好了

原文地址:https://www.cnblogs.com/hwt987/p/3665979.html