yii2 urlmanager remove parameters from url

I’m trying to find a way to configure the UrlManager to remove all parameters from a Url.

The case is that of a pagination on a listview where I have defined a rule to put the page numbers as part of the main url:-

                    'collections/<name:.*?>/<type:\d+>/page/<page:\d>' => '/search/results',

                    'collections/<name:.*?>/<type:\d+>' => '/search/results',


As you can see it is being diverted to a controller called search, which is using the route to hardcode the search parameter from the type variable in the url.

However, the pagination object, in ‘createUrl’, is adding back some of the GET parameters such as searchForm[type].

Is there a way to configure the urlManager to truncate all parameters? or do I need to extend it and do this myself?

It’s virtually impossible to remove the get parameters (query strings) from the url.

Probably you’d better change the pjax behavior instead.

Try this with your view script:

<?php Pjax::begin(['enablePushState' => false,]); ?>

<?= GridView::widget(...

  ... (grid view code) ...


<?php Pjax::end(); ?>

“enablePushState” is true, by default. And it brings the lengthy query strings back to the url bar of the user’s browser. By setting it to false, you can suppress this behavior.

But note that you will lose some goodies that pjax could otherwise give you.