M
M
Maxim2018-11-03 23:53:44
Yii
Maxim, 2018-11-03 23:53:44

Yii How to redirect from backend/web/?

Hello! The question is simple, but I can not solve it in any way.
Can you tell me how to make a redirect in htaccess of all links that have backend/web. For example, when a request

crm.topjam.ru/sk-orto/backend/web/help/rating

You need to remove /backend/web from it and redirect to a new request:
crm.topjam.ru/sk-orto/help/rating

The project is in the sk-orto subfolder, not in the root.
config
$baseUrl = str_replace('/backend/web', '', (new Request)->getBaseUrl());
'request' => [
            'csrfParam' => '_csrf-backend',
            'baseUrl' => $baseUrl
        ],

htaccess
# deal with admin first
    RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
    RewriteRule ^assets/(.*)$ backend/web/assets/$1 [L]
    RewriteRule ^css/(.*)$ backend/web/css/$1 [L]
    RewriteRule ^js/(.*)$ backend/web/js/$1 [L]
    RewriteRule ^images/(.*)$ backend/web/images/$1 [L]
    RewriteRule ^(.*)$ backend/web/$1 [L]

    # if request begins with /admin remove admin and ad /backend/web/
    RewriteCond %{REQUEST_URI} ^/admin
    RewriteRule ^admin\/?(.*) /backend/web/$1

    # other requests add /frontend/web/$1
    RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|admin)
    RewriteRule (.*) /backend/web/$1

    # if backend request
    RewriteCond %{REQUEST_URI} ^/backend/web
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /backend/web/index.php

With these settings, the address crm.topjam.ru/sk-orto/backend/web gives a 404 error, but if you add index.php , then backend/web/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2018-11-04
@VladimirAndreev

Or maybe change the tail root in the webserver config?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question