干净的网址&在yii2中使用.htaccess重写URL

时间:2015-08-10 12:21:23

标签: yii2 yii2-advanced-app yii-url-manager

如何在yii2中将此网址设为http://localhost/yii-application/frontend/web/site/booking更简单?

http://localhost/yii-application/frontend/web/site/booking

我需要更简单:

http://localhost/controller/action

我如何使用.htaccess处理此问题

1 个答案:

答案 0 :(得分:0)

通过放置此网址管理器:

    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        // Disable index.php
        'showScriptName' => false,
        // Disable r= routes
        'enablePrettyUrl' => true,
        'rules' => [
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

        ] ]

您将实现

 http://localhost/yii-application/controller/action