我用Yii2高級模板創建了一個網站,我想訪問位於「根」文件夾中的上傳文件夾中的文件。 我:Yii2如何訪問「root」文件夾中的文件夾?
backend/web/
frontend/web/
uploads/
我遵循的Yii2. Access to higher level folder
一號答案所以我的.htaccess是
Options +FollowSymlinks
RewriteEngine On
# deal with backend first
RewriteCond %{REQUEST_URI} /(backend)
RewriteRule ^backend/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^backend/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^backend/image/(.*)$ backend/web/image/$1 [L]
RewriteCond %{REQUEST_URI} !/backend/web/(assets|css|image)/
RewriteCond %{REQUEST_URI} /(backend)
RewriteRule ^.*$ backend/web/index.php [L]
RewriteCond %{REQUEST_URI} /(assets|css|js|img|font)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^img/(.*)$ frontend/web/img/$1 [L]
RewriteCond %{REQUEST_URI} !/(frontend|backend)/web/(assets|css|js|img|font)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
我共同/組件/ Request.php文件
<?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{
return parent::resolvePathInfo();
}
}
}
?>
我的前置/ config/main.php
..
'components' => [
'request' => [
'cookieValidationKey' => 'xxxxxxxxxxxxxxxxx',
'csrfParam' => '_csrf-frontend',
'class' => 'common\components\Request',
'web'=> '/frontend/web'
],
現在我可以訪問我的網站與本地主機/ MYAPP(不含/前端/網/)
之前,我可以在影像中看到我的上傳文件夾
Html::img('../..'/uploads/my-image.png')
但它確實不工作了,沒有../../uploads nore與上傳/
我怎樣才能訪問上傳文件夾?
謝謝你的回答。但我無法修改vhost配置,因爲我的服務器由Plesk管理,而我沒有SSH訪問權限,是否有另一種解決方案? – Ludo