How to remove the controller name from the URL, when the module is called when it is requested

We have

http: //yii.local/ Module / Controller / Action

Need to

http: //yii.local/Module/Action

    1 answer 1

    In the component settings, use the following rules:

    'urlManager' => [ 'showScriptName' => false, // Disable index.php 'enablePrettyUrl' => true, // Disable r= routes 'rules' => [ '<module:(my-module-name)>/<action:(my-action-name)>' => '<module>/my-controller-name/<action>', ] ], 

    Read more in the documentation section of the rules of routing.

    • one
      Is it in /config/web.php ? I ask something, I just did it, too, but something tells me that somehow it needs to be done inside the module - after all, he and the module. - Roman Grinyov
    • one
      @RomanGrinyov You did everything right. A module is simply a module of an application that performs routing requests. The urlManager component can also be attached to the module, but the entry point is the application itself. - Andrey Kolomensky
    • one
      Компонент urlManager можно и к модулю прикрепить — it is configured in the module class using Yii::configure() as described here ; where in the config.php do so ? But then the rules that we define in this configuration do not work; ... is it because the entry point is the application itself? Sorry, if a stupid question, I just do not fully understand the workflow Yii2? - Roman Grinyov
    • one
      By the way, I would be grateful for the information on workflow Yii2 - I’m certainly trying to do it myself, looking at the source, to understand it, but the info wouldn’t hurt. - Roman Grinyov
    • one
      @RomanGrinyov you understand everything correctly :) yiiframework.com/doc-2.0/guide-structure-overview.html - I can only advise this material. Trying and watching the source is one of the best ways! - Andrey Kolomensky