[英]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.