Did you try in your config:
'defaultRoute' => 'user/index'
Like few people already said, you need to add
defaultRoute in the configurations file.
Here is how it should look:
//config/web.php in basic template or
backend/config/main.php in advanced
$config = [ ... 'components' => [ ... ], 'params' => $params, 'defaultRoute' => 'user/index', ];
This can be set within the config, see Default Controller:
[ 'defaultRoute' => 'main', ]
But note that this is closely related to routing, which can be completely customized by
urlManager component. Then if you want let’s say
domain/profile to behave like
domain/user/profile then these rules for
urlManager might be another way to go:
'rules' => array( '<action:\w+>' => 'user/<action>', // <-- use UserController by default '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ),
Hopefully this will help someone 🙂
web.php file from your configuration folder, and add the following:
'defaultRoute' => 'admin'
With yii2 I was able to do it in the urlmanager with:
'rules'=> [ ['pattern'=>'<action>', 'route'=>'controller/<action>'], ]
This is not the answer of question, however it might be helpful to know:
there is a
catchAll property in
yii\web\Application which is defined as:
The configuration specifying a controller action which should handle all user requests.
'catchAll' => ['controller/action']
So, every request to http://basic.com will call
Try the other solutions… If they do not work, then use my simple trick…
Just create an index.php page at the root.
Then, in that file, write this code:
return header('Location: http://your page location');
defaultRoute is ignored, when
strictParsing is set to enabled in the
urlManager config. Refer to the issue on GitHub: https://github.com/yiisoft/yii2/issues/5892
The following config is recommended as a measure:
[ ... 'defaultRoute' => 'default/index', ... 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, ... 'rules' => [ ... '' => '', // <- this line should be added ], ], ... ]
If ‘defaultRoute’ don’t work – check settings for ‘urlManager’. Maybe default route is set there.
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '' => 'site/index', // this line should be chenged to ''=>''. '<controller:\w+>/<action:\w+>/' => '<controller>/<action>', ], ],