M
M
Maxim Ustinov2016-03-28 18:43:20
Yii
Maxim Ustinov, 2016-03-28 18:43:20

How to remove duplicates after setting cnc urls in Yii2?

Hello!
I ask for help from Yii2 experts. I'm using the basic app.
I registered the following UrlManagera settings in config/web.php:

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [
                ['class' => 'app\components\SeoUrlRule', 'connectionID' => 'db'],
            ],
        ]

I also created a component that inherits the UrlRule class, in which I assigned the createUrl and parseRequest methods, they convert route to slug and vice versa, according to the table in the database.
And everything works fine (in general, Yii2 is very pleasing, I'm just starting to get acquainted with it).
But at the standard framework addresses (like domen.com/index.php?r=category/index&id=2) we get to the home page. Any other addresses that don't have an id - slug match throw a 404 error.
In the parseRequest() method, I have this code:
elseif (!$request->getPathInfo()) {
            return [ 'home/index', [] ];
        }

That is, if there is nothing after the domain name, we do not go into the database to find a match for this slug, but direct it to the main page. But it turns out that requests like domen.com/index.php?r=category/index&id=2 also fall under this condition, since if I remove this condition, then similar requests and an attempt to enter the main page will result in a 404 error
. course, tell me how to make these addresses also issue 404? And is it necessary?
PS Changed config/web.php:
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            //'enableStrictParsing' => true,
            'rules' => [
                //['class' => 'app\components\SeoUrlRule', 'connectionID' => 'db'],
            ],
        ]

That is, I turned off the class that processes urls, and still, with PrettyUrl enabled, the url of the form /index.php?r=category/index&id=2 leads to the main page. Is Yii2 designed this way? Or are my crooked hands so arranged?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question