K
K
Ken Jee2016-08-30 20:41:10
Yii
Ken Jee, 2016-08-30 20:41:10

How to organize a redirect to a page in Yii2 without a slash at the end?

Suppose there is a page address that ends with a slash... How to teach Yii2 when requesting such a page to perform a 301 redirect to the same page, but without a slash at the end? Plus, you need to remember about the parameters.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-08-30
@Machez

In general, this should be done through mod_rewrite:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

You can also add rules for specific urls in urlManager:
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            	'controller/action/' => 'controller/action',
            ]
        ],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question