I have a laravel project (version 5.8 if being specific) where CSS and js files are in subdirectories in public directory, for example, there is a www.mysite.test/css/app.css that I want to allow. But I would like to redirect users if they try to access a url like www.mysite.test/css
currently, it shows a blank white screen, and it is not desired.
Important: Files in the directory must be accessible
This question has been answered here. see this Link!
Just add in your upload folder .htaccess file with content:
Deny from all
what you need to do is to add this code in your web.php routes, for exemple:
Route::fallback(function () {
return redirect()->back();
});
source : Laravel Docs
Two options here,
Basically you add an index.php
file in your css
directory and you use this index file to redirect the users with something like this
<?php
header('Location: http://www.mysite.test/');
?>
Or you can use it to allow only selected files to be read from everyone.