Yii2 .htaccess阻止访问后端图像
问题描述:
我在我的yii2根目录中有.htaccess文件来隐藏前端/网页,并且我正在上传yii2-app/uploads中的图像。 问题是我无法访问后端图像RewriteRule ^(.*)$ frontend/web/$1 [L]
,如果我删除这一行然后图像可访问,但前端/网页出现在url中,我该如何解决这个问题?我如何创建访问图像的特殊规则?Yii2 .htaccess阻止访问后端图像
在网格视图:
[
'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]
+0
也是一个高级的配置,可以通过存储代替上传到使存储目录被找到 –
请参阅我的回答http://*.com/questions/38426427/yii2-access-to-higher-level-folder/38428685#38428685 – vishuB