Yii2 UrlManager Breaks On Periods

I am currently using yii2 urlmanager to create a pretty url. It receives a parameter and then look up users based on it. Unfortunately, if the parameter contains a period, it won’t run at all and redirects to a 404 page.

So, mysite.com/me/jbroad

works perfectly, but


returns a 404 page.

Here is my url manager code

        'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '' => 'site/index',
            'me/<id:\w+>' => 'kit/page',
            'generate/<id:\w+>' => 'kit/generate',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

Hi @walker6o9, welcome to the forum.

The regular expression \w is a shortcut for [a-zA-Z_0-9] and doesn’t contain period. You may try something like the following:

'me/<id:[\w\.]+>' => 'kit/page',
1 Like