Yii2.htaccess阻止访问后端的映像


Yii2 .htaccess prevent to access images in backend

我在yii2根目录中有.htaccess文件来隐藏前端/web,我正在yii2-app/uploads中上传图像。问题是,由于这一行RewriteRule ^(.*)$ frontend/web/$1 [L],我无法访问后端的图像,如果我删除这一行,那么图像是可以访问的,但前端/web显示在url中,我如何解决这个问题?如何创建访问图像的特殊规则?

在网格视图中:

[
 'label' => 'Image', 
 'attribute' => 'banner', 
 'format' => 'raw',   
 'value' => function ($data) {
      return Html::img(Yii::$app->request->baseUrl.'../../../uploads/'.$data->banner, ['alt'=>$data->title,'width'=>'20','height'=>'30']); 
   }
],   

.htaccess:

Options -Indexes
<IfModule mod_rewrite.c> 
  RewriteEngine on
  #RewriteCond %{REQUEST_URI} !^public
  RewriteRule ^(.*)$ frontend/web/$1 [L] 
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^'.|/'.) - [F]

目录结构:

yii2-app
   --backend
   --frontend
   --uploads

我在RewriteRule ^(.*)$ frontend/web/$1 [L]之前添加了这个规则,并为我工作。

RewriteCond %{REQUEST_URI} /(uploads)
RewriteRule ^uploads/(.*)$ uploads/$1 [L]