throw new NotFoundHttpException and Not allowed actions are being redirected to application default action

Whenever there is throw new NotFoundHttpException or Not allowed actions when I send an ajax request the response is being the website default page.

I don’t understand why is it acting like that but I would like those two response to be considered as error to ajax resquest and to not send the website as response.

How can I do that?

I am think may be it my .htaccess configuration? of which I am not sure.


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php