I want to use subdomain as id, and I need dynamic router to do this. In urlManager, I added this line:
"http://<user:\w+>.local.dev/<controller:\w+>/<action>" => '<controller>/<action>',
When I try any action, for example:
function actionMyAccount($user){
echo $user;...
}
I am not getting anything - the var isn't printed, and script stops working (screen is white). When I remove $user, the page is loading without any problems
How can I achieve subdomain router?
I think your router mapping setting is OK. If you want it to be more precise:
"http://<user:[^www]\w+>.local.dev/<controller:\w+>/<action:\w+>" => '<controller>/<action>'
But to make it work, you'd better double check following two things:
First, your virtual host should have a
*.local.dev
server_name
innginx
ServerAlias
inApache
Then you can use dynamic controller's name as subdomain.
Second, your virtual host should have been configured
rewrite
rules correctly, refer to Yii2 doc.e.g. for
Apache
, just create a.htaccess
file underYOUR_APP/web/
folder with following content lines: