Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 使用htaccess使特定目录下的php文件不可访问_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 使用htaccess使特定目录下的php文件不可访问

Apache 使用htaccess使特定目录下的php文件不可访问,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个.htaccess文件,用于重定向未命中现有文件或目录的所有请求,以供index.php文件解析,如下所示: <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / # Our app bootstrap file is index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Rewrit

我有一个.htaccess文件,用于重定向未命中现有文件或目录的所有请求,以供index.php文件解析,如下所示:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  # Our app bootstrap file is index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

重新启动发动机
重写基/
#我们的应用程序引导文件是index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
这很好,但我还想添加另一条规则,防止直接访问某个目录下的php文件,将这些调用路由到同一个index.php文件

像这样:

请求example.com/something.php->ok

请求example.com/themes/(anythinggoesher)/somefile.php->not 好的,route toul index.php

请求example.com/themes/(anythinggoesher)/banner.png->ok

我正在寻找一种方法,使那些“规则”适用于“主题”文件夹下的所有内容,而不破坏我当前的规则


谢谢

您可以使用新规则来处理这些
.php
请求:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /

  # handle .php requests via index.php
  RewriteCond %{REQUEST_URI} !^/themes/ [NC]
  RewriteRule ^[^/]+/.+?\.php$ index.php?/$1 [L,NC]

  # Our app bootstrap file is index.php
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

重新启动发动机
重写基/
#通过index.php处理.php请求
重写cond%{REQUEST_URI}^/主题/[NC]
重写规则^[^/]+/.+?\.php$index.php?/$1[L,NC]
#我们的应用程序引导文件是index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]

非常感谢!在这里和那里做了一些调整,以适应其他需要,但我得到了这个想法。