user1780370
user1780370

Reputation: 851

404 Not Found in Yii2 regarding API new module

I am developing Yii2 project where create api module in it but have a issue to call api where got error of page not found.

How to call that api controller which i created. I Run below url for api call.

The requested URL /project/project_name/api/v1/api/login was not found on this server.

What i have to change or any configuration required for it. I am missing something anywhere. Any one have experience or trick to solved it.

Thanks in Advance.

Upvotes: 0

Views: 2120

Answers (2)

Rahul Mankar
Rahul Mankar

Reputation: 990

Adding below code into my main.php solved the 404 not found issue:

        'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => false,
        'showScriptName' => false,
        'rules' => [
            [
                'class' => 'yii\rest\UrlRule',
                'controller' => 'user',
            ],
        ],
    ]

I was trying to set enableStrictParsing to true for the urlManager but still the same then try this,

'enableStrictParsing' => false,

Ref. Link

Upvotes: 1

meysam
meysam

Reputation: 1794

It can cause by two reasons:

  1. Module is not loaded. You must add it to your config/web.php (Or if this module may run under Command environment, also add to config/console.php) under modules key.
  2. Your routing is not well-configured. For fix, you can add your url as key and value to your UrlManager module on config/web.php and try for browsing. If it fixed that, you can define a pattern for your url.

If any help is needed, please do not hesitate to submit comment on my answer.

Upvotes: 0

Related Questions