I find it difficult to configure my .htaccess and urlManager in a Yii project to have an interface in http://www.example.com and a backend in http://www.example.com/backend with the following folder structure. Any help is appreciated. Thanks.
/assets /backend /controllers /config main.php /models /views /common /models /protected /controllers /config main.php /models /views .htaccess backend.php index.php
Solution: after a lot of help @ bool.dev all that it works, so I add here every necessary final file. In the interface, I use the path format for url and hide index.php
/backend/config/main.php
$backend=dirname(dirname(__FILE__)); Yii::setPathOfAlias('backend', $backend); return array( 'basePath' => $backend, 'controllerPath' => $backend.'/controllers', 'viewPath' => $backend.'/views', 'runtimePath' => $backend.'/runtime', ...);
/protected/config/main.php
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ),
.htaccess
Options +FollowSymLinks IndexIgnore */* <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /yii/example/ RewriteRule backend backend\.php [T=application/x-httpd-php]
backend.php
$yii=dirname(__FILE__).'/../../yii/framework/yii.php'; $config=dirname(__FILE__).'/backend/config/main.php'; require_once($yii); Yii::setPathOfAlias('common', dirname(__FILE__).DIRECTORY_SEPARATOR.'common'); Yii::createWebApplication($config)->run();
index.php
$yii=dirname(__FILE__).'/../../yii/framework/yii.php'; $config=dirname(__FILE__).'/protected/config/main.php'; require_once($yii); Yii::setPathOfAlias('common', dirname(__FILE__).DIRECTORY_SEPARATOR.'common'); Yii::createWebApplication($config)->run();