Php 是否使用.htaccess阻止对文件和子目录的访问?
我有将近30个php文件,在我的目录中有4个子目录。我想阻止用户直接查看一些php文件和子目录,如Php 是否使用.htaccess阻止对文件和子目录的访问?,php,.htaccess,Php,.htaccess,我有将近30个php文件,在我的目录中有4个子目录。我想阻止用户直接查看一些php文件和子目录,如http://bhavani.com/hai.php 我的当前htaccess文件 ## Enable Mod Rewrite, this is only required once in each .htaccess file RewriteEngine On RewriteBase / ## Test for access to includes directory RewriteCond
http://bhavani.com/hai.php
我的当前htaccess
文件
## Enable Mod Rewrite, this is only required once in each .htaccess file
RewriteEngine On
RewriteBase /
## Test for access to includes directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /includes/ .*$ [NC]
## Test that file requested has php extension
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
## Forbid Access
RewriteRule .* - [F,NS,L]
怎么做?我认为您只能使用RewriteRule而不能使用RewriteCond 例如:
RewriteRule^/hai\.php-[F,NS,L]
此规则禁止访问hai.php文件
对于其他文件,您可以使用其他规则或使用掩码。您可以像这样筛选文件
<Files ~ "\.php$">
Deny from all
</Files>
<Directory "/subdirectory">
Deny from all
</Directory>
全盘否定
像这样的目录
<Files ~ "\.php$">
Deny from all
</Files>
<Directory "/subdirectory">
Deny from all
</Directory>
全盘否定
您不需要mod\u rewrite
来完成此操作。一种更简单的方法是使用mod_alias
中的RedirectMatch
指令:
RedirectMatch 403 ^.*/include/*\.php$
这将自动对
include
子目录中任何PHP文件的直接请求做出403禁止
响应,但是您仍然可以从其他PHP文件中包含它们。您可以在PHP文件的开头创建一个简单的if()语句,如用户登录或任何您需要的访问权限,如果没有,则标题(“404”);出口它会删除所有文件。但是我想要一些像索引这样的文件。php@jayamalladi,为index.php