Yii2 - subdomain routing

房东的猫 提交于 2019-12-01 18:34:57

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 in nginx
  • or ServerAlias in Apache

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 under YOUR_APP/web/ folder with following content lines:

Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!