简体   繁体   English

Laravel 5.8-如何保护存储目录免受路由影响?

[英]Laravel 5.8 - How to protect Storage Directory from routing?

I'd like to protect my files inside Storage Directory, but when I accessing the storage directory from address bar, all of my storage files appear like this : 我想保护存储目录中的文件,但是当我从地址栏中访问存储目录时,我所有的存储文件都显示如下: 在此处输入图片说明

What I want is, if user inserting /storage keywords to the URL or address bar, it will redirected to 404 Page or somewhere else. 我想要的是,如果用户在URL或地址栏中插入/storage关键字,它将重定向到404页面或其他位置。

Route::get('/storage', function(){
  // What Should I do here?
});

Seems like your site's root directory is wrong. 似乎您网站的根目录错误。

The domain name should point to the public folder inside Laravel's root directory ( for a default configuration ). 该域名应该指向Laravel的根目录内的公共文件夹(默认配置 )。 This way your storage folder and all other directories stay outside and can not be reached using browser. 这样,您的存储文件夹和所有其他目录都位于外部,无法使用浏览器访问。

And it might be a good idea to disable directory indexing in your Web server's configuration . 最好在Web服务器的配置中禁用目录索引。 If using Apache - you can put the following option in to your .htaccess file: 如果使用Apache-您可以将以下选项放入.htaccess文件中:

Options -Indexes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM