Yii2 api in shared host

I’m trying to host a rest api with yii2 basic template. My application structure is this:


+ web

  +.htaccess

  +index.php

+ config

+ controllers

...

+ api

  + config

  + modules

    + v1

      + controllers

  .htaccess

  index.php



I’m bit newbie in host process, so: Where should I put the api directory? public_html ? Or should I leave this structure and modify the permissions ?

I think this is the correct structure, but when I try to GET some URI, I get the 404 http error.


+ public_html(or www, or web)

      +.htaccess

      +index.php        

      + api

        + config

        + modules

          + v1

            + controllers

        .htaccess

        index.php

Someone has faced this situation? Thank you!

Maybe you didn´t pluralize your url…

Please post your config and the url you tried.

Api.php


<?php

 

$db     = require(__DIR__ . '/../../config/db.php');

$params = require(__DIR__ . '/../../config/params.php');

 

$config = [

    'id' => 'basic',

    'name' => 'ApiComparador',

    // Need to get one level up:

    'basePath' => dirname(__DIR__).'/..',

    'bootstrap' => ['log'],

    'components' => [

        'request' => [

            // Enable JSON Input:

            'parsers' => [

                'application/json' => 'yii\web\JsonParser',

            ]

        ],

		'user' => [

            'identityClass' => 'app\models\Usuario',

        ],

        'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['error', 'warning'],

                     // Create API log in the standard log dir

                     // But in file 'api.log':

                    'logFile' => '@app/runtime/logs/api.log',

                ],

            ],

        ],

        'urlManager' => [

            'enablePrettyUrl' => true,

            'enableStrictParsing' => true,

            'showScriptName' => false,

            'rules' => [

                ['class' => 'yii\rest\UrlRule', 'controller' => 'v1/estabelecimento'],

				['class' => 'yii\rest\UrlRule', 'controller' => 'v1/usuario', 'extraPatterns' => ['POST login' => 'login']],

				['class' => 'yii\rest\UrlRule', 'controller' => ['ap' => 'v1/altera-preco'], 'extraPatterns' => ['POST pesquisa' => 'pesquisa', 'GET historico/{id}' => 'historico']],

				['class' => 'yii\rest\UrlRule', 'controller' => ['etp' => 'v1/estabelecimento-tem-produto']],				

				['class' => 'yii\rest\UrlRule', 'controller' => 'v1/lista', 'extraPatterns' => ['GET itens/{id}' => 'itens', 'GET calcula/{id}' => 'calcula', 'GET usuario/{id}' => 'usuario' ]],

				['class' => 'yii\rest\UrlRule', 'controller' => ['ltp' => 'v1/lista-tem-produto']],

				['class' => 'yii\rest\UrlRule', 'controller' => 'v1/localizacao'],

				['class' => 'yii\rest\UrlRule', 'controller' => 'v1/produto'],

            ],

        ], 

        'db' => $db,

    ],

    'modules' => [

        'v1' => [

            'class' => 'app\api\modules\v1\Module',

        ],

    ],

    'params' => $params,

];

 

return $config;

I’m trying to GET [baseUrl]/api/v1/estabelecimentos. Without pluralize, same issue. In localhost works fine. I suspect that is the apache config. Because it’s redirecting…