Настраиваем проект на Yii2 Advanced под Apache на одном домене. Такая конфигурация часто востребована на shared-хостинге.

В корень проекта добавляем .htaccess:

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

<IfModule mod_rewrite.c>
 # если /admin, то в backend
 RewriteCond %{REQUEST_URI} ^/(admin)
 RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
 RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
 RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]
 RewriteCond %{REQUEST_URI} !^/backend/web/(assets|js|css|js)/
 RewriteCond %{REQUEST_URI} ^/(admin)
 RewriteRule ^.*$ backend/web/index.php [L]
 RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
 RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
 RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
 RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
 RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
 RewriteRule ^(.*)$ frontend/web/$1 [L]
 RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
 RewriteCond %{REQUEST_URI} !index.php
 RewriteCond %{REQUEST_FILENAME} !-f [OR]
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^.*$ frontend/web/index.php
</IfModule>

admin - путь к @backend/web, его можно заменить на то, что вам больше нравится, например на administrator.

В директорию @frontend/web добавляем файл .htaccess:

AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>	
 Options -Indexes
 RewriteEngine On
 # Обрезаем www + https
 RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
 #RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
 #RewriteCond %{HTTPS} off
 #RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
 # Обрезаем слэш в конце строки в адресе
 RewriteCond %{REQUEST_URI} ^(.+)/$
 RewriteRule ^(.+)/$ /$1 [R=301,L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . index.php
</IfModule>

# кеш браузера
<ifModule mod_expires.c>
 ExpiresActive On
 #по умолчанию кеш в 5 секунд
 ExpiresDefault "access plus 1 days"
 # Включаем кэширование изображений и флэш на месяц
 ExpiresByType image/x-icon "access plus 1 month"
 ExpiresByType image/jpg "access plus 4 weeks"
 ExpiresByType image/jpeg "access plus 4 weeks"
 ExpiresByType image/png "access plus 30 days"
 ExpiresByType image/gif "access plus 43829 minutes"
 ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
 # Включаем кэширование css, javascript и текстовых файлоф на одну неделю
 ExpiresByType text/css "access plus 604800 seconds"
 ExpiresByType text/javascript "access plus 604800 seconds"
 ExpiresByType application/javascript "access plus 604800 seconds"
 ExpiresByType application/x-javascript "access plus 604800 seconds"
 # Включаем кэширование html и htm файлов на один день
 ExpiresByType text/html "access plus 43200 seconds"
 # Включаем кэширование xml файлов на десять минут
 ExpiresByType application/xhtml+xml "access plus 600 seconds"
 # Нестандартные шрифты сайта
 ExpiresByType application/x-font-ttf "access plus 1 month"
 ExpiresByType font/opentype "access plus 1 month"
 ExpiresByType application/x-font-woff "access plus 1 month"
 ExpiresByType image/svg+xml "access plus 1 month"
 ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
</ifModule>
<IfModule mod_setenvif.c>
 BrowserMatch "MSIE" force-no-vary
 BrowserMatch "Mozilla/4.[0-9]{2}" force-no-vary
</IfModule>
# сжатие text, html, javascript, css, xml:
<ifModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>

В файле @frontend/config/main.php в секции components:

'request' => [
 'baseUrl' => '',
],
'urlManager' => [
  //'hostInfo' => 'https://site.com',
  'enablePrettyUrl' => true,
  'showScriptName' => false,
  'enableStrictParsing' => true,
  'rules' => [
  '' => 'site/index',
  '<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
  ],
 ],
],

В директорию @backend/web добавляем файл .htaccess:

AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
 Options -Indexes
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . index.php
</IfModule>

В файле @backend/config/main.php в секции components:

'request' => [
 'baseUrl' => '/admin',
],
'urlManager' => [
 //'hostInfo' => 'https://site.com/admin',
 'enablePrettyUrl' => true,
 'showScriptName' => false,
 'rules' => [
  '' => 'site/index',
  '<_a:login|logout>' => 'auth/<_a>',
  '<_c:[\w\-]+>' => '<_c>/index',
  '<_c:[\w\-]+>/<id:\d+>' => '<_c>/view',
  '<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>',
  '<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_c>/<_a>',
 ],
],