htaccess的保护所有子文件夹和放大器;档放大器、文件夹、htaccess

2023-09-02 20:34:42 作者:食物昵称好听大全 适合吃货的女生

我有这种情况:

/storage
  index.php
  other scripts.php
  /files  
    -files and folders-

我要拒绝所有的HTTP请求中的所有文件和 /文件子文件夹,但在同一时间允许访问 /存储和运行这些PHP脚本。我尝试了一些规则,但他们要么保护的文件只上市或不允许访问所有的 /存储文件夹。

I want to deny all the HTTP requests to all files and subfolders of /files but in the same time allowing to access /storage and run those PHP scripts. I tried some rules but they either protect only the listing of files or don't allow access to all the /storage folder.

的.htaccess 必须是外 /文件(因为这个文件夹是由PHP访问用readfile 的.htaccess 可以访问)。

The .htaccess must be outside /files (because this folder is accessed by PHP readfile and .htaccess could be accessible).

推荐答案

在IE下 /储存根.htaccess文件目录,就把这行:

In your root .htaccess file i.e. under /storage directory put this line:

RewriteRule ^files/ - [R=404,L,NC]

这将引发 404 来的任何东西文件/ 子目录下的所有HTTP请求,而你的的.php 文件就可以包含在文件文件/ 子目录。

This will throw 404 to all the HTTP requests for anything under files/ sub directory while your .php files will be able to include files under files/ sub directory.