Quantcast
Viewing latest article 5
Browse Latest Browse All 18

How to Enable Optional Trailing Slash in Yii2 URLs

Inspired from Github

If you have links, that might end with slashes (sometimes they are being added automatically), you won’t be able to handle them unless you add a string to your Yii2 project configuration.

Since version 2.0.10 UrlManager can be configured to handle trailing slashes in a simple way. Just make sure your config file has normalizer parameter:

'urlManager' => [
            'showScriptName' => false,
            'enablePrettyUrl' => true,
            'normalizer' => [
                'class' => 'yii\web\UrlNormalizer'
                ],

You’re done! Now you can use trailing slashes and everything will be routed correctly.


Viewing latest article 5
Browse Latest Browse All 18

Trending Articles