繁体   English   中英

Yii2 .htaccess阻止访问后端中的图像

[英]Yii2 .htaccess prevent to access images in backend

我的yii2根目录中有.htaccess文件,用于隐藏前端/网络,并且正在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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM