简体   繁体   中英

Laravel storage link keep redirected to /public directory in hosting

I'm using a hosting service to upload my laravel project and link it to laravel's public directory using php header location in laravel's root directory. Then I created a storage link in public directory using symlink or artisan command, but when I'm trying to access the files it always redirected to /public, I wonder why?

Header location index.php

<?php 
    header('Location: public/');
?>

The image link:

存储目录下的图片链接

But when I'm trying to view the image by clicking the image link, it always redirected to /public directory

Result Image

结果图像

You can create .htaccess in your root and add these lines and check.

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

First, you make a .htaccess file and write this code

RewriteEngine On RewriteCond %{REQUEST_URI}.^/public/ RewriteRule ^(,*)$ /public/$1 [L,QSA]

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