PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 5, 2022

[FIXED] Can't make the UrlManager Rules work in Yii2

 March 05, 2022     yii, yii2     No comments   

Issue

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.


Solution

$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



Answered By - rob006
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing