Answer the question
In order to leave comments, you need to log in
How to remove names of all controllers from url in Yii2?
For example, there are User, Site, etc. controllers. It is necessary that during the transition the name of the controller was not displayed in the url.
Instead of:
site.com/user/auth
Was:
site.com/auth
__________________________________________
Instead of:
site.com/site/contact
Was:
site.com/contact
Answer the question
In order to leave comments, you need to log in
I will supplement the answer from Ilya Karavaev
All this is configured in the urlManager configuration, for example, if All requests in which there is no controller must be redirected to SiteController, then this can be done like this:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<action>' => 'site/<action>',
]
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/contact' => 'site/contact',
'/auth' => 'user/auth'
]
],
Via urlManager. You just need to make the right list of rules (rule). And you will most likely have to do this for every such shorthand, because you need to explicitly specify where to send the request to Yii itself anyway.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question