简体   繁体   中英

yii2 image path giving 404 error in img tag

Image is not accessible in img tag. View code is as follows:-

<?= Html::img(Yii::getAlias('@web').'/web/uploads/'.$model->logo, ['alt'=>'some', 'class'=>'thing']);?>

删除/ web

<?= Html::img(Yii::getAlias('@web').'/uploads/'.$model->logo, ['alt'=>'some', 'class'=>'thing']);?>

could be the relative path

<?= Html::img(Yii::getAlias('@web'). '.'. 
       DIRECTORY_SEPARATOR . 'uploads' .DIRECTORY_SEPARATOR .$model->logo, 
        ['alt'=>'some', 'class'=>'thing']);?>

made some changes in .htaccess file, and the problem is solved.

Options +FollowSymlinks
RewriteEngine On

# deal with admin first
RewriteCond %{REQUEST_URI} ^/advanced/(admin)
RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^admin/uploads/(.*)$ backend/web/uploads/$1 [L]

RewriteCond %{REQUEST_URI} !^/advanced/backend/web/(assets|css|uploads)/  
RewriteCond %{REQUEST_URI} ^/advanced/(admin) 
RewriteRule ^.*$ backend/web/index.php [L]


RewriteCond %{REQUEST_URI} ^/advanced/(assets|css) 
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]

RewriteCond %{REQUEST_URI} !^/advanced/(frontend|backend)/web/(assets|css|uploads)/  
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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