Home > database >  Laravel storage link keep redirected to /public directory in hosting
Laravel storage link keep redirected to /public directory in hosting

Time:11-29

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

CodePudding user response:

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

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

CodePudding user response:

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

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

  • Related