休息 yii2 漂亮 url url 经理

rest yii2 pretty url urlManager

我的 yii2 rest 可以很好地处理这个请求 http://extractor-frontend.dev/property?id=JP000004 我愿意用这个 http://extractor-frontend.dev/property/JP000004

这是我在 config/web 中的 urlManager。php

urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,

        'rules' => [
            [
                'class'=>'yii\rest\UrlRule',
                'pluralize' => false,
                'controller' => 'property',

                'tokens' => [
                    '{id}' => '<id:\w+>'
                ],
                'extraPatterns' => ['GET,HEAD property/{id}' => 'index',]

            ]
        ],
    ],

这是我在网络中的 .htaccess

RewriteEngine on
Options Indexes
Require all granted
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php

if put 'enableStrictParsing' => false,

http://extractor-frontend.dev/site/about 工作正常...重写规则有效!

我在我的 yii2 应用程序中使用了以下代码。我认为您的配置方法符合 yii1 的要求。推荐使用yii2配置方式

 'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            'myaction/<id>/<param2>' => 'site/myaction',

            [
                'pattern' => '<action>',
                'route' => 'site/<action>',
                'defaults' => ['action' => 'index']
            ],
        ]
    ]