休息yii2漂亮url urlManager

时间:2016-10-09 11:01:06

标签: yii2 yii2-advanced-app yii-rest

我的yii2休息与此请求一起工作正常 this article 我会用这个 http://extractor-frontend.dev/property?id=JP000004

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

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

如果放'enableStrictParsing'=&gt;假,

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

1 个答案:

答案 0 :(得分:0)

我在yii2应用程序中使用以下代码。我认为您的配置方法符合yii1的条件。建议使用yii2配置方法。

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

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