R
R
Roma Antonyuk2017-10-23 11:25:24
Yii
Roma Antonyuk, 2017-10-23 11:25:24

How to redirect from /site/index to / in yii2?

How to redirect via htaccess file from /site/index to / ?
Example.com/site/index - should lead to a redirect to example.com If possible, give an example of my urlmanager

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'rules' => [
                '' => 'site/index',
                '<slug>' => 'site/category',
                '<category_slug>/<page_slug>' => 'site/page'
            ],
        ],

my htaccess
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
</IfModule>

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} ^/.*
    RewriteRule ^(.*)$ web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/web/
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ web/index.php
</IfModule>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-10-23
@webinar

Why a redirect? It is just necessary that site / index does not appear in the project

'rules' => [
                '/' => 'site/index',
]

And make all links through url helper
Url::toRoute(['site/index']) //будет генерить '/'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question