I check the link to the resource through the service and show that error 302, although the view says that error 404. How can I make it so that it really gives 404 error? Or am I misunderstanding something?

  • the easiest way to do this in htaccess is user33274
  • Something is in doubt that the service simply catches the first answer, which is indeed 302, but after it has worked out what is found, it returns 404, which the service does not catch ... - Roman Grinyov

2 answers 2

You can catch the InvalidRouteException exception in Module::runAction() to make sure that the error is really in accessing a non-existent resource. To force a response code to 404, you can use the method: Yii::$app->response->setStatusCode(404); .

Learn more about installing the response code here: http://www.yiiframework.com/doc-2.0/yii-web-response.html#setStatusCode%28%29-detail

    You can throw an exception

     throw new NotFoundHttpException();