htaccess阻止index.php以外的direct.php文件
我想阻止直接访问.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
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文件