我尝试将 Yiiinitializr 站点结构用于我的 Yii 项目。结构如下所示:
root
--backend
----standart yii folders
----...
----www
------index.php (admin.mysite.com)
--common
----common folders for backend and frontend
----...
--backend
----standart yii folders
----...
----www
------index.php (mysite.com)
问题是如何制作这样的工作 URL:
admin.mysite.com/invites - in backend
和
mysite.com/users - in frontend
当我在虚拟主机上上传项目时出现路由问题。后端例如:
admin.mysite.com/backend/www/?r=site/invites - working properly
admin.mysite.com/backend/www/invites - working properly
admin.mysite.com/?r=site/invites - working properly
admin.mysite.com/invites - redirects to index
根文件夹有自己的 .htaccess 包含以下内容:
RewriteEngine On
RewriteRule ^backend/www/ - [last]
RewriteCond %{HTTP_HOST} admin.mysite.com [nocase]
RewriteRule (.*) backend/www/$1 [last]
RewriteRule ^frontend/www/ - [last]
RewriteCond %{HTTP_HOST} !admin.mysite.com [nocase]
RewriteRule (.*) frontend/www/$1 [last]
backend/www/.htaccess 有重写规则:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
Yii urlManagers 代码:
'urlManager' => array(
// uncomment the following if you have enabled Apache's Rewrite module.
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
// default rules
'<page:\w+>' => 'site/<page>',
'' => 'site/index',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
),