D
D
ddddd tttt2019-02-20 14:53:33
Yii
ddddd tttt, 2019-02-20 14:53:33

How to remove slash using Yii1?

return [
    ...
    'on beforeRequest' => function () {
        $pathInfo = Yii::$app->request->pathInfo;
        $query = Yii::$app->request->queryString;
        if (!empty($pathInfo) && substr($pathInfo, -1) === '/') {
            $url = '/' . substr($pathInfo, 0, -1);
            if ($query) {
                $url .= '?' . $query;
            }
            Yii::$app->response->redirect($url, 301);
            Yii::$app->end();
        }
    },
    ...
];

I tried to remove the slash, add code to the configuration file, but for some reason it says "property not defined". And in index through the on method it doesn't work, the error "method is not defined".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
l4m3r, 2019-02-20
@l4m3r

Dude, this is done at the web server level, not code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question