Answer the question
In order to leave comments, you need to log in
Yii2 advanced, what is the best way to solve the issue with index files?
Installed Yii2 advanced. The index.php files remained in backend/web and frontend/web.
Implemented access to them like this, .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
# deal with admin first
RewriteCond %{REQUEST_URI} ^/(admin|assets|css|js|images)
RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^admin/js/(.*)$ backend/web/js/$1 [L]
RewriteRule ^admin/images/(.*)$ backend/web/images/$1 [L]
RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
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>
echo Url::toRoute(['/users/all', 'page' => 2], true);
echo Url::toRoute(['/users/all', 'page' => 2]);
http://site.ru/admin/users/all?page=2
/admin/users/all?page=2
...
'components' => [
'request' => [
'enableCsrfValidation' => true,
'enableCookieValidation' => true,
'baseUrl' => '/admin'
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// Модуль
'users/all/page/<page>' => 'users/default/all',
'users/all' => 'users/default/all',
//'<_a:(login|logout|error|captcha)>' => 'admin/default/<_a>',
]
],
....
echo Url::toRoute(['/users/all', 'page' => 2]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question