A
A
Alexander Stepanov2019-10-01 22:37:39
Yii
Alexander Stepanov, 2019-10-01 22:37:39

How to set up a 301 redirect in Yii2 for addresses like /catalog/trikotazh?page=1?


The rules in .htaccess do not seem to be designed for /blog/category?page=1 and never work with such an address (probably because of the characters for regular expressions). addresses...
How to make /blog/category?page=1 become /blog/category

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2019-10-02
@Exebeche

Good morning.
Leave .htaccess and query string checking alone)))
Everything is solved much easier.

$dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
               'defaultPageSize' => 20,
               'forcePageParam' => false,
            ]
        ]);

With these settings, pagination for the first page will not show page=1 and will not show per-page in the page address.
So you do not need to set up a redirect in .htaccess for this, and even more so do any checks in the controller, as @Giperoglif advises
ps If you still use htaccess, then the following directives should work
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} (?:^|&)page=1 [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]

G
Gip, 2019-10-02
@Giperoglif

do not like .htaccess - do it right in the controller return $this->redirect('/blog/category');by the presence of the page==1 parameter in the querystring

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question