I adjusted module api, and created controller UserController extends ActiveController. All work fine, but view return 404 error.
- http://example.com/api/user/45 – return 404 (Error)
- http://example.com/api/user/view/?id=45 - return 200 (Ok)
Why yii\rest\UrlRule don't work in this case?
Info from official page about this rule:
GET /users/123: return the details of the user 123;
ANSWER:
- Set yii\rest\UrlRule::$pluralize property to false;
- Set enableStrictParsing to false.
1- Be sure to have the same configs as shown in related docs:
2- Enabling Pretty Url in Yii requires further configurations at server level. For example if server is apache a similar configs to those should be added to htaccess file:
More details and related configs to nginx can be found in the getting started section. Also check those tutorials for basic and advanced templates:
3- Depending on the project structure there is cases where you'll need to use RewriteBase or equivalent to define the base path holding your app. Like adding this to an apache's htaccess file:
4- From the rest quick start guide:
Which means endpoint url is expected to look like http://example.com/api/users/45 by default.