InterviewSolution
Saved Bookmarks
| 1. |
How to enable the pretty URL format in Yii2? |
|
Answer» Create an .htaccess file and add this code. RewriteEngine on # If a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise FORWARD it to index.php RewriteRule . index.php 2. Now Modify common/config/main-local.php 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, 'rules' => array( '<controller:\W+>/<id:\d+>' => '<controller>/VIEW', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ), ], |
|