The CORRECT and COMPLETE answer is that you have to use the rule like below.
'rules' => [
'products/<name:[\-\w]+>' => 'products/show',
],
then in your products controller you don't need to pass $name in the parameter anymore that is why we defined in the rule and you have to use the
Yii::$app->request->queryParams['name']; or Yii::$app->request->get('name') to get the name of the product, your action will look like below
public function actionShow()
{
echo Yii::$app->request->get('name');
}
after doing all the settings above open brower and type
http://yourdomain.com/products/some-product
and it will show you
some-product
When you have to create a link to that page lets say in menu you have under products all products listed and you have to create a link to detail page for all of them i.e actionShow you would do it like below.
<?=Html::a($model->name,
Yii::$app->urlManager->createUrl([
'products/show',
'name'=>$model->slug
])
);
?>