Skip to content

Instantly share code, notes, and snippets.

@nkarpeev
Created August 24, 2018 22:02
Show Gist options
  • Save nkarpeev/7a2e1f4a58427eb4f0452058b0b3f625 to your computer and use it in GitHub Desktop.
Save nkarpeev/7a2e1f4a58427eb4f0452058b0b3f625 to your computer and use it in GitHub Desktop.
yii2 advanced admin panel on one domain
//on backend
return [
'homeUrl' => '/adminpanel',
'components' => [
'request' => [
'baseUrl' => '/sm-admin',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
],
],
],
];
//on frontend
return [
'homeUrl' => '/',
'components' => [
'request' => [
'baseUrl' => '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
],
],
],
];
//on app/.htaccess
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# Если запрос начинается с /sm-admin, то заменяем на /backend/web/
RewriteCond %{REQUEST_URI} ^/sm-admin
RewriteRule ^sm-admin\/?(.*) /backend/web/$1
# Добавляем другой запрос /frontend/web/$1
RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|sm-admin)
RewriteRule (.*) /frontend/web/$1
# Если frontend запрос
RewriteCond %{REQUEST_URI} ^/frontend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/web/index.php
# Если backend запрос
RewriteCond %{REQUEST_URI} ^/backend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /backend/web/index.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment