Wednesday, August 12, 2015

Hướng dẫn cấu hình Enable clean URL in yii2 php Loại bỏ url thuần đi

Hướng dẫn cấu hình  Enable clean URL in yii2 php Loại bỏ url thuần đi
Giúp cho các bạn có thể thay đổi đường dẫn theo controller và action.
Tạo file .htaccess
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
Tiếp theo vào config ,tại web.php thêm vào phần 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>',
        ),
        ],

0 comments:

Post a Comment