Hi i want to make url like this in yii2
example.com/pagename
example.com/folder1/pagename
example.com/folder1/folder2/pagename
My code
path:- site/pages/folder1/folder2/
Add this in main-local.php
'< view >' => 'site/pages',
'folder1/< view >' => 'site/folder1',
'folder2/< view >' => 'site/folder1/folder2',
at sitecontroller i add this first is working but second is not working 404 error
'pages' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' =>'pages',
],
'folder1' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' =>'pages/folder1',
],
'folder2' => [
'class' => 'yii\web\ViewAction',
'viewPrefix' =>'pages/folder1/folder2',
],
Any suggestions?
i was used a method like yours need i hope its help you. but i didn't test folder2. So you can test and send me results,too.:)
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<folder:\w+>/<controller:\w+>/<action:\w+>' => '<folder>/<controller>/<action>',
),
]
]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.