Step-by-step instruction

Step 1

At the root of the project (@app) add a .htaccess with the following content:

  1. <IfModule mod_rewrite.c>
  2. Options +FollowSymlinks
  3. RewriteEngine On
  4. </IfModule>
  5.  
  6. <IfModule mod_rewrite.c>
  7. RewriteCond %{REQUEST_URI} ^/(admin)
  8. RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
  9. RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
  10. RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]
  11. RewriteCond %{REQUEST_URI} !^/backend/web/(assets|js|css|js)/
  12. RewriteCond %{REQUEST_URI} ^/(admin)
  13. RewriteRule ^.*$ backend/web/index.php [L]
  14. RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
  15. RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
  16. RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
  17. RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
  18. RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
  19. RewriteRule ^(.*)$ frontend/web/$1 [L]
  20. RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
  21. RewriteCond %{REQUEST_URI} !index.php
  22. RewriteCond %{REQUEST_FILENAME} !-f [OR]
  23. RewriteCond %{REQUEST_FILENAME} !-d
  24. RewriteRule ^.*$ frontend/web/index.php
  25. </IfModule>

Where admin - path to the @backend/web.

Step 2

In the folder @frontend/web add the file .htaccess with the following content:

  1. RewriteEngine on
  2.  
  3. # if a directory or a file exists, use it directly
  4. RewriteCond %{REQUEST_FILENAME} !-f
  5. RewriteCond %{REQUEST_FILENAME} !-d
  6.  
  7. # otherwise forward it to index.php
  8. RewriteRule . index.php

Step 3

In the file @frontend/config/main.php in item components of array add:

  1. 'request' => [
  2. 'baseUrl' => '',
  3. ],
  4. 'urlManager' => [
  5. 'enablePrettyUrl' => true,
  6. 'showScriptName' => false,
  7. 'rules' => [
  8. '' => 'site/index',
  9. '<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
  10. ],
  11. ],

Step 4

In the folder @backend/web add the file .htaccess with the following content:

  1. RewriteEngine on
  2.  
  3. # if a directory or a file exists, use it directly
  4. RewriteCond %{REQUEST_FILENAME} !-f
  5. RewriteCond %{REQUEST_FILENAME} !-d
  6.  
  7. # otherwise forward it to index.phpp
  8. RewriteRule . index.php

Step 5

In the file @backend/config/main.php in item components of array add:

  1. 'request' => [
  2. 'baseUrl' => '/admin',
  3. ],
  4. 'urlManager' => [
  5. 'enablePrettyUrl' => true,
  6. 'showScriptName' => false,
  7. 'rules' => [
  8. '' => 'site/index',
  9. '<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
  10. ],
  11. ],

Well done)