NaturalBornCamper
NaturalBornCamper

Reputation: 3866

Can't make the UrlManager Rules work in Yii2

I understand many variables outside what I can provide could be the problem, but I'm still asking if someone had this problem and could help.

Here's my UrlManager config in the components

    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => false,
        'showScriptName' => true,
        'rules' => [
            '' => 'site/index',
            'member' => 'site/login',
        ],
    ],

This url works:

http://exampler.com/web/index.php?r=site/login

This url returns a 404

http://example.com/web/index.php?r=member

**NOTE: ** I don't have any messy Nginx or Apache rules on my server like this guy had. My rules seem to be completely ignored, whatever I write in them.

Upvotes: 0

Views: 92

Answers (1)

rob006
rob006

Reputation: 22144

$rules is ignored if you set $enablePrettyUrl to false. From $rules documentation:

The rules for creating and parsing URLs when $enablePrettyUrl is true. This property is used only if $enablePrettyUrl is true.

https://www.yiiframework.com/doc/api/2.0/yii-web-urlmanager#$rules-detail

Upvotes: 1

Related Questions