Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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
htaccess阻止index.php以外的direct.php文件_Php_.htaccess_Utf 8 - Fatal编程技术网

htaccess阻止index.php以外的direct.php文件

htaccess阻止index.php以外的direct.php文件,php,.htaccess,utf-8,Php,.htaccess,Utf 8,我想阻止直接访问.php文件。下面这两行就行了 RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.+)\.php - [F,L] 但是,它不会打开index.php文件。我想阻止直接访问.php文件,除了index.php文件添加一个不将规则应用于特定文件的条件: RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule !^index\.php$ - [F,L] RewriteCond $1

我想阻止直接访问.php文件。下面这两行就行了

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php - [F,L]

但是,它不会打开index.php文件。我想阻止直接访问.php文件,除了index.php文件

添加一个不将规则应用于特定文件的条件:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !^index\.php$ - [F,L]
RewriteCond $1 !^(index\.php)$

要防止直接访问除
index.php
之外的所有
.php
文件,可以使用以下规则:

RewriteCond %{THE_REQUEST} \.php[?/] [NC]
RewriteRule !^index\.php$ - [F,L,NC]
您需要为此使用
%{THE_REQUEST}
变量
_REQUEST
变量表示Apache从浏览器收到的原始请求,在执行某些重写规则后不会被覆盖

Options +FollowSymlinks
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !^(.+).css$ 
RewriteCond %{REQUEST_FILENAME} !^(.+).js$ 
RewriteCond %{REQUEST_FILENAME} !index.php$ 
RewriteRule ^(.+)$ /deny/ [nc] 

访问文件“CSS”和“JS”以及“index.php”将在那里。其他请求将被重定向到“拒绝”文件夹。

甚至图像、css、javascript也可能重复?@frz3993仅PHP文件