我的项目中有以下目录:
我想通过此网址指向后端(yii2 app):http://localhost/Project/backend,而前端(angular)应该是根,http://localhost/Project。
依此类推,我想通过以下网址呼叫控制器{
"Id":"123",
"Product": "test",
"Tags":[
{
"Name": "name",
"Categories": [
{
//item 1
},
{
//item 2
},
{
//item 3
}
]
},
{
"Name": "name",
"Categories": [
{
//item 1
},
{
//item 2
},
{
//item 3
}
]
}
]
}
:http://localhost/Project/backend/api。
我到目前为止所尝试的内容:
.htaccess(项目):
api
.htaccess(项目/后端):
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/Project
RewriteRule ^.*$ frontend/backend/web/index.php [L]
RewriteCond %{REQUEST_URI} ^/obeauty/(admin)
RewriteRule ^.*$ backend/backend/web/index.php [L]
.htaccess(项目/后端/后端):
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/Project/(backend)
RewriteRule ^backend/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^backend/css/(.*)$ backend/web/css/$1 [L]
Request.php(Project / backend / common / components):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
main.php(Project / backend / backend / config):
<?php
namespace common\components;
class Request extends \yii\web\Request {
public $web;
public $adminUrl;
public function getBaseUrl(){
return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl;
}
public function resolvePathInfo(){
if($this->getUrl() === $this->adminUrl){
return "";
}else{
$pathInfo = parent::resolvePathInfo();
return $pathInfo == 'index.php' || $pathInfo == 'index.php/' ? 'site/index' : $pathInfo;
}
}
}