我很難在Yii項目中配置我的.htaccess和urlManager,使用以下文件夾結構在http://www.example.com和http://www.example.com/backend中有前端。歡迎任何幫助。謝謝。Yii:用於獨立後端和前端的.htaccess和urlManager
/assets
/backend
/controllers
/config
main.php
/models
/views
/common
/models
/protected
/controllers
/config
main.php
/models
/views
.htaccess
backend.php
index.php
解決方案: @ bool.dev一切它的工作有極大的幫助後,讓我在這裏將每一個需要的最終文件。在前端我使用的路徑格式的URL和隱藏的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]
# 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
</IfModule>
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();
你能告訴我你爲什麼沒做後端模塊? –
我想遵循強描述的Yii的項目現場http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/的目錄結構。 – Puigcerber
你不應該有一個單獨的htaccess的後端,後端文件夾中?,說讓example.com的外htaccess的,並建立內部後端另一個htaccess的,對於example.com/backend –