How to remove the name of any of the controllers from the URL in Yii2
There is such a urlManager
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'<action:\w+>' => 'site/<action>',
],
In the root of the www project, there is one .htaccess
<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>
And in the web folder such
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
There are also two controllers with site and auth, there will be more of them in the raging one. how can I make all of them look like this type of URL? mysite.ru/(any of the actions here)?
0
Author: Maxim Lyubitelev, 2019-01-29
1 answers
Try configuring the urlManager like this:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
'pattern' => '',
'route' => 'site/index',
],
[
'pattern' => '<action>/<id:\w+>',
'route' => '<controller>/<action>',
'suffix' => ''
],
[
'pattern' => '<action>',
'route' => '<controller>/<action>',
'suffix' => ''
],
],
],
0
Author: phpNT, 2019-01-31 14:02:45