0
我需要使用URL管理中心從隱藏控制器和漂亮的URL與Yii2
http://www.domain.com/index.php?r=tamil-article/articles&categ=Innovation&id=44
更改URL中Yii2到
http://www.domain.com/44/Innovation.html
行動如何才能做到這一點?
我需要使用URL管理中心從隱藏控制器和漂亮的URL與Yii2
http://www.domain.com/index.php?r=tamil-article/articles&categ=Innovation&id=44
更改URL中Yii2到
http://www.domain.com/44/Innovation.html
行動如何才能做到這一點?
您可以通過配置UrlManager使用prettyUrls解決這個問題。
之後,你可以添加自定義URL規則的規則陣列(在配置/ main.php):
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Add the .html suffix
'suffix' => '.html',
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => [
'<id:\d+>/<categ:\w+>' => 'tamil-article/articles',
],
],
謝謝Szántó佐爾坦! 能否請你解釋一下如何做。在此先感謝.. –
您可以匹配的URL控制器,動作和參數。這些位於規則陣列,其中所述鍵是自定義路由和值是控制器和動作路線中.. –