我想防止直接.php文件訪問。這下面2行工作正常htaccess防止直接.php文件除index.php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php - [F,L]
但是,它不會打開index.php文件。我想,以防止除了的index.php文件
我想防止直接.php文件訪問。這下面2行工作正常htaccess防止直接.php文件除index.php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.php - [F,L]
但是,它不會打開index.php文件。我想,以防止除了的index.php文件
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !^index\.php$ - [F,L]
直接PHP文件訪問添加條件的規則並不適用於特定的文件:
RewriteCond $1 !^(index\.php)$
爲了防止所有.php
直接訪問除了index.php
您可以使用此規則文件:
RewriteCond %{THE_REQUEST} \.php[?/] [NC]
RewriteRule !^index\.php$ - [F,L,NC]
您需要使用%{THE_REQUEST}
變量 這個。 THE_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」將在那裏。其他請求將重定向到「拒絕」文件夾。
[拒絕直接訪問除index.php以外的所有.php文件]的可能副本(http://stackoverflow.com/questions/1340001/deny-direct-access-to-all-php-files-except-index -php) –
即使圖像,CSS,JavaScript呢? – frz3993
@ frz3993只有PHP文件 –