拒绝访问除子目录中的文件以外的所有文件

拒绝访问除子目录中的文件以外的所有文件

问题描述:

I am trying to restrict access to all files in my home directory, then to allow only one main php file from a subdirectory using one .htaccess file, but it does not work as expected. It shows only "Forbidden" for every request. How to make it work as expected?

Now I am using :

order allow,deny

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /path_to_file/index.php [QSA]

我试图限制访问我的主目录中的所有文件,然后只允许一个主要的php文件来自 使用一个.htaccess文件的子目录,但它不能按预期工作。 它仅为每个请求显示“禁止”。 如何让它按预期工作? p>

现在我正在使用: p>

  order allow,deny 
 
RewriteEngine On 
RewriteCond%  {REQUEST_URI} ^ / $ [OR] 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteRule。* / path_to_file/index.php [QSA] 
  code>  pre> 
  div>

You can just forward all requests to that particular file. Put this in your root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} !/subdir/file\.php$ [NC]
RewriteRule ^ /subdir/file.php [QSA]