2

我尝试将 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)

空白 Yiinitializr 结构见 github

问题是如何制作这样的工作 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>',
    ),
),
4

1 回答 1

1

在聊天讨论后更新
: 所有问题都在$_SERVER['SCRIPT_NAME'],它等于/backend/www/index.php。这就是为什么解析请求CHttpRequest::getPathInfo是空值的原因,因为 $baseUrl (它不是 $_SERVER['SCRIPT_NAME'] 的 basedir '')和$_SERVER['PHP_SELF'] == $_SERVER['SCRIPT_NAME'].

两种解决方案:

  1. 设置在 index.php 的开头$_SERVER['SCRIPT_NAME'] = '/index.php';
  2. 使该子域直接admin.example.com看到目录/backend/www/
于 2013-10-30T10:55:17.457 回答