0

I have the following url manager path

        'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            '<controller:(\w|-)+>/' => 'site/index',
            '<module:api\w+>/<controller:\w+>/<action:(\w|-)+>' => '<module>/<controller>/<action>',
         ],
    ]

What am looking for is all urls not rendered via api module paths to run via site/index but all other paths having api/* to be executed via module paths.

The above works for urls like /login, /auth but when i run urls like

/administrative/uom 

It fails

SO basically i want all urls to be redirrected via site/index but all urls having api as the prefix like api/auth/login to be run via their respective controllers. I have added an api module which should handle this.

What else do i need to add to make this work?

Geoff
  • 6,277
  • 23
  • 87
  • 197

1 Answers1

1

When adding rules always start from more detailed to less detailed. And you added general rule for controller only so no URL with action is matched. Do this

'rules' => [
    'api/<controller:\w+>/<action:[\w\-]+>' => 'api/<controller>/<action>',
    '<controller:[\w\-]+>/<action:[\w\-]+>' => 'site/index',
    '<controller:[\w\-]+>/' => 'site/index',
],
Bizley
  • 17,392
  • 5
  • 49
  • 59
  • Thanks this works for the general routes but api routes doesn't work. Note that api is a module. From your answer a visit to api/auth still call site/index – Geoff Aug 05 '19 at 08:19
  • In that case add `'api/' => 'api/'` as well as second rule – Bizley Aug 05 '19 at 08:26
  • Bizley i faced a new issue with this, when i access a deep routed url like administrative/stores-registers/registers or even administrative/stores-registers/registers/test it doesnt call site/index it tries to resolve via controller/action. How do i adjust this further to work even with many paths – Geoff Aug 12 '19 at 10:50