As per your question in conjunction with your comments, I suggest that you additionally add a rule for a blank url pattern, i.e. for url with domain only, that is directed to your defaultRoute with a default $page parameter value.
'rules' => [
[
'pattern' => '',
'route' => 'site/index',
'defaults' => ['page' => 1],
],
[
'pattern' => 'page/<page:\d+>',
'route' => 'site/index',
],
],
Then, in your controller action you can test this url rule is working as follows:
public function actionIndex($page)
{
echo '<pre>';
echo 'site / index / $page ' . print_r($page, true);
echo '</pre>';
exit;
}
Also note that you could set the default in the method declaration of your controller action like so:
public function actionIndex($page = 1)
{
echo '<pre>';
echo 'site / index / $page ' . print_r($page, true);
echo '</pre>';
exit;
}
Which would allow you to simplify your config as follows:
'rules' => [
[
'pattern' => '',
'route' => 'site/index',
],
[
'pattern' => 'page/<page:\d+>',
'route' => 'site/index',
],
],
example.com/page/1route to be accessed via urlexample.com, then later pages viaexample.com/page/2,example.com/page/3etc?'defaultRoute' => 'site/index'?example.comnow open site/index, my problem is when inexample.com/page/2click on previous page in pagination, instead example.com opened example.com/page