A
A
akula222018-02-13 14:20:40
Yii
akula22, 2018-02-13 14:20:40

How do I give 404 for existing links?

A request of the form
/?r=blablaor any similar one /?mod=blabla
opens a page from 'defaultRoute' => 'site/default/index',
And I want it to give out 404.
How to do this?
Here is my wheel

'enablePrettyUrl' => true,
    'enableStrictParsing' => false,
    'showScriptName' => false,
    'rules' => [
        '<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
    ],

if 'enableStrictParsing' => false, turn to true then yes, but when opening a site without a request, i.e. site.ru opens a 404 error from
'errorHandler' => [
            'errorAction' => 'site/default/error',
        ],

defaultRoute stops working (
Tell me where is the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-02-13
@OKyJIucT

You can, for example, check for the existence of a GET parameter and issue a 404 error like this
throw new \yii\web\NotFoundHttpException();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question