T
T
Tanya2016-12-13 14:33:29
Yii
Tanya, 2016-12-13 14:33:29

301 Redirect 404 pages to nginx, will yii framework work?

Hello everyone, tell me if the rule for 301 redirects will work?
You need to glue pages giving 404 errors with existing
if (isset($get['page']) && isset($get['number']) && isset($get['brand']) && 'goods_info' == $get ['page'] {
Yii::$app->response->redirect(['/catalog/', 'slug' => Inflector::slug(Inflector::transliterate($get['number'] . '- ' .$get['brand']))], 301);
return;
}
// SITE.ru/goods_info?brand=NISSAN&number=A6860EC09A this page throws a 404 error
// SITE.ru/catalog/a6860ec09a-nissan.html this page exists

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Toey, 2016-12-14
@Toey

You need to make sure that all requests like "SITE.ru/goods_info?brand=NISSAN&number=A6860EC09A" fall into the actionGoodsInfoRedirect (for example) and in this action write your redirtect 301
in the Yii config

'urlManager'=>array(
            //... ваши правила
     'rules'=>array(
                'goods_info'=>'site/goodsInfoRedirect',
           ),
),

add action to SiteController.php controller
public function actionGoodsInfoRedirect(){
        if (isset($get['number']) && isset($get['brand']) ) {
Yii::$app->response->redirect(['/catalog/', 'slug' => Inflector::slug(Inflector::transliterate($get['number'] . '-' . $get['brand']))], 301);
return;
}
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question