有没有办法如果有人访问我的laravel项目中的目录,我会将它们重定向到主页?

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,

1. Using an index.php

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/');
?>

2. .htaccess

Or you can use it to allow only selected files to be read from everyone.