Skip to content
Advertisement

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 :

Image link under storage directory

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

Result Image

Result Image

Advertisement

Answer

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

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement