Answer the question
In order to leave comments, you need to log in
How to remove default and index using Yii routing rules?
Hello! I can not fully understand the rules of urlManager . I use both controllers and modules. I'm trying to remove the names in the address bar in controllers and modules that have index, defaul and view. I'm trying to remove these names from the address bar with the following rules:
'rules' => [
//'/' => 'event/default/index',
//'event/<id:\d+>' => 'event/view',
'<_a:(login|signup|add-user)>' => 'site/<_a>',
'<_c:[\w-]+>' => '<_c>/index',
'<_c:[\w-]+>/<id:\d+>' => '<_c>/view',
'<_c:[\w\-]+>/<_a:[\w-]+>' => '<_c>/<_a>',
'<_m:[\w\-]+>' => '<_m>/default/index',
'<_m:[\w\-]+>/<id:\d+>' => '<_m>/default/view',
'<_m:[\w\-]+>/<id:\d+>/<c>' => '<_m>/default/<_a>',
'<_m:[\w\-]+>/<_c:[\w\-]+>' => '<_m>/<_c>/index',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>' => '<_m>/<_c>/view',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>/<id:\d+>' => '<_m>/<_c>/<_a>',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
]
Answer the question
In order to leave comments, you need to log in
Good morning.
Details about routing rules can be found here . The sound is lame, but you can understand.
You can use .htaccess to remove index and defaul from the address bar.
On the example of a basic application, it looks like this:
In the web .htaccess directory
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} ^/web/*
RewriteRule . index.php
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
'showScriptName' => false,
$baseUrl = str_replace('/web', '', (new Request)->getBaseUrl());
'request' => [
'cookieValidationKey' => ADFAEk3o9dfhwleSDFo',
'baseUrl' => $baseUrl,
],
'' => 'site/default/index',
'contact' => 'site/contact/index',
'<_a:(error)>' => 'site/default/<_a>',
// это правило для модуля users
'<_a:(login|logout|signup|password-rest-request|email-confirm|reset-password)>' => 'users/default/<_a>',
'<_m:[\w\-]+>' => '<_m>/default/index',
'<_m:[\w\-]+>/<_c:[\w\-]+>' => '<_m>/<_c>/index',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>' => '<_m>/<_c>/view',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>/<_a:[\w\-]+>' => '<_m>/<_c>/<_a>',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question