Php Yii2.htaccess禁止访问后端中的图像
我的yii2根目录中有.htaccess文件,用于隐藏frontend/web,我正在yii2 app/uploads中上载图像。 问题是我无法访问后端的图像,因为这一行Php Yii2.htaccess禁止访问后端中的图像,php,.htaccess,yii2,yii2-advanced-app,Php,.htaccess,Yii2,Yii2 Advanced App,我的yii2根目录中有.htaccess文件,用于隐藏frontend/web,我正在yii2 app/uploads中上载图像。 问题是我无法访问后端的图像,因为这一行RewriteRule^(.*)$frontend/web/$1[L],如果我删除这一行,则图像可以访问,但前端/web出现在url中,我如何解决这个问题?如何为access图像创建特殊规则 在网格视图中: [ 'label' => 'Image', 'attribute' => 'banner', 'fo
RewriteRule^(.*)$frontend/web/$1[L]
,如果我删除这一行,则图像可以访问,但前端/web出现在url中,我如何解决这个问题?如何为access图像创建特殊规则
在网格视图中:
[
'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]
我在为我工作的
RewriteRule^(.*)$frontend/web/$1[L]
之前添加了此规则
RewriteCond %{REQUEST_URI} /(uploads)
RewriteRule ^uploads/(.*)$ uploads/$1 [L]
在高级配置中也可以参考我的答案,您可以用存储替换上传,以找到存储目录
RewriteCond %{REQUEST_URI} /(uploads)
RewriteRule ^uploads/(.*)$ uploads/$1 [L]