Yii: .htaccess and urlManager for separate backend and frontend

末鹿安然 提交于 2019-12-03 14:51:12

According to this wiki article by Qiang, you could make the following changes and it should work:

// backend.php:
require('path/to/yii.php');
Yii::createWebApplication('backend/config/main.php')->run();

Then in your backend's config (i.e backend/config/main.php):

$backend=dirname(dirname(__FILE__));
$frontend=dirname($backend);
Yii::setPathOfAlias('backend', $backend);

return array(
    'basePath' => $backend,

    'controllerPath' => $backend.'/controllers',
    'viewPath' => $backend.'/views',
    'runtimePath' => $backend.'/runtime',

    'import' => array(
        'backend.models.*',
    ),
    // ... other configurations ...
);

But for this to work we need the main .htaccess to route example.com/backend to backend.php, which i haven't figured out yet.

Edit:
Just figured out:

RewriteEngine On
RewriteBase /projectroot/
RewriteRule backend backend\.php [T=application/x-httpd-php]

The RewriteBase was important for me, as the backend.php was not found when i hadn't given the correct projectroot, basically it should be the directory where you have the entry script backend.php.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!