3

I have a url like this

http://localhost/yii2/category/my-custom-string-parameter

I need to get the text my-custom-string-parameter

And I setup the rules like this

'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>',
                    'category/<url:>' => 'category/view',
            ),
        ],

This always give me 404 error. What should I do?

adeade
  • 317
  • 5
  • 12

1 Answers1

6

replace 'category/<url:>' => 'category/view',, with 'category/<id:\w+>' => 'category/view'

Routing to View need an id and to use a string use w+ not url:

Don Vincent
  • 466
  • 4
  • 15
  • 2
    Actually the part before the ":" is just the name that will be used to store the value in the GET variables. "url" is perfectly fine if that is a better name than "id". The regex behind the ":" is what needs to match and the OPs code didn't work because the regex was missing completely – Blizz May 16 '15 at 09:03