Pagination Yii2如何从url中删除站点/索引和页面参数

Pagination Yii2如何从url中删除站点/索引和页面参数,pagination,yii2,Pagination,Yii2,我在默认页面上使用分页,即yii2中的站点/索引。因此,链接器为分页生成的URL如下所示 domain.com/site/index?page=1 'site/index/<page:\d+>' => 'site/index' $pagination->route = '/'; '/<page:\d+>' =>'site/index'; 我想删除site/index和page参数,如下所示 domain.com/1 domain.com/sit

我在默认页面上使用分页,即yii2中的站点/索引。因此,链接器为分页生成的URL如下所示

domain.com/site/index?page=1
'site/index/<page:\d+>' => 'site/index'
$pagination->route = '/';
'/<page:\d+>' =>'site/index';
我想删除site/index和page参数,如下所示

domain.com/1
domain.com/site/index/1

我试着像这样在配置文件的URL管理器中编写规则

domain.com/site/index?page=1
'site/index/<page:\d+>' => 'site/index'
$pagination->route = '/';
'/<page:\d+>' =>'site/index';

为了同时删除站点/索引,我将分页路由设置为“/”,如下所示

domain.com/site/index?page=1
'site/index/<page:\d+>' => 'site/index'
$pagination->route = '/';
'/<page:\d+>' =>'site/index';
这从URL中删除了站点/索引,但这再次将URL更改为

domain.com/?page=1
domain.com/1

我试着像这样在URL管理器中更改规则

domain.com/site/index?page=1
'site/index/<page:\d+>' => 'site/index'
$pagination->route = '/';
'/<page:\d+>' =>'site/index';

我正在使用Yi2高级模板,并在URL管理器中启用了严格解析。

我使用以下组件配置在本地计算机上实现了此功能:

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'baseUrl' => 'http://example.dev',
    'rules' => [
        [
            'pattern' => '<page:\d+>',
            'route' => 'site/index'
        ]
    ],
]

很抱歉,此配置不适用于我。我得到一个(#404)错误页面。可能是因为我在URL管理器中将
'enableStrictParsing'
设置为
true
。我不明白为什么会出现问题-您可以临时将'enableStrictParsing'设置为false,以验证这是否是问题。您是否已确保接受$page作为操作的参数?