Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Yii:.htaccess和urlManager用于单独的后端和前端_.htaccess_Yii_Frontend_Backend - Fatal编程技术网

Yii:.htaccess和urlManager用于单独的后端和前端

Yii:.htaccess和urlManager用于单独的后端和前端,.htaccess,yii,frontend,backend,.htaccess,Yii,Frontend,Backend,我很难在Yii项目中配置my.htaccess和urlManager,使前端和后端具有以下文件夹结构。欢迎任何帮助。谢谢 /assets /backend /controllers /config main.php /models /views /common /models /protected /controllers /config main.php /models /views .htaccess backe

我很难在Yii项目中配置my.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',

...);
'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>',
    ),
),
/protected/config/main.php

$backend=dirname(dirname(__FILE__));
Yii::setPathOfAlias('backend', $backend);
return array(
'basePath' => $backend,

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

...);
'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>',
    ),
),
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();
根据,您可以进行以下更改,并且应该可以正常工作:

// backend.php:
require('path/to/yii.php');
Yii::createWebApplication('backend/config/main.php')->run();
然后在后端的配置(即backend/config/main.php)中:

但要使其正常工作,我们需要main.htaccess将example.com/backend路由到backend.php,我还没有弄清楚这一点

编辑:
刚刚发现:

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

RewriteBase
对我来说很重要,因为在我没有给出正确的projectroot时找不到backend.php,基本上,它应该是你有输入脚本backend.php的目录。

你能告诉我你为什么不把backend作为一个模块吗?我想遵循羌所描述的Yii项目网站的目录结构。你不应该在backend文件夹中有一个单独的htaccess for backend吗?,假设在example.com中创建外部htaccess,并在后端中创建另一个htaccess,example.com/backendmy最后的注释可能与此无关。因此,您主要关心的是如何将example.com/backend映射/路由到“backend”文件夹?是的,没错,我有两个输入脚本:
index.php
用于前端,而
backend.php
用于后端。在文件夹后端和受保护的内部,我有
.htaccess
拒绝所有人
。到目前为止,没有任何东西,该指南是我第一次尝试遵循,但没有办法让它工作…事实上,我尝试了你的目录结构,它工作了,所以你能告诉我确切的错误吗?或者您遇到的问题?您在.htaccess中只有那三行吗?是的,但是根据您看到的错误,您可以尝试添加更多类似于
选项+索引+FollowSymLinks
,如果您告诉我错误,那么我们可以尝试其他方法
RewriteEngine On
RewriteBase /projectroot/
RewriteRule backend backend\.php [T=application/x-httpd-php]