Answer the question
In order to leave comments, you need to log in
How to redirect to admin login using htacces in an advanced project?
How to make a redirect to enter the admin panel of an advanced project in htacces.
Here is the root htaccess code:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteRule (.*) web/$1
RewriteRule ^(.*)$ frontend/web/index.php
RewriteRule ^admin(.+)$ backend/web/$1 [L,PT]
Answer the question
In order to leave comments, you need to log in
In the configuration file backend/main.php or backent/main-local.php do the following:
<?php
use yii\web\Request;
$baseUrl = str_replace('/backend/web', '/admin', (new Request())->getBaseUrl());
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'your_validation_key',
'baseUrl' => $baseUrl
],
],
];
}
return $config;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin(/.*)?$ backend/web/$1 [L]
# handle the case of frontend
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^(.*)$ frontend/web/$1 [L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question