簡體   English   中英

htaccess防止除index.php之外的直接.php文件

[英]htaccess prevent direct .php files except index.php

我想防止直接.php文件訪問。 這2行以下工作正常

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

但是,它不會打開index.php文件。 我想阻止直接的.php文件訪問,但index.php文件除外

添加一個條件以不將規則應用於特定文件:

RewriteCond $1 !^(index\.php)$

為了防止直接訪問除index.php之外的所有.php文件,可以使用以下規則:

RewriteCond %{THE_REQUEST} \.php[?/] [NC]
RewriteRule !^index\.php$ - [F,L,NC]

您需要為此使用%{THE_REQUEST}變量。 THE_REQUEST變量表示Apache從您的瀏覽器收到的原始請求,在執行某些重寫規則后不會被覆蓋。

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule !^index\.php$ - [F,L]
Options +FollowSymlinks
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !^(.+).css$ 
RewriteCond %{REQUEST_FILENAME} !^(.+).js$ 
RewriteCond %{REQUEST_FILENAME} !index.php$ 
RewriteRule ^(.+)$ /deny/ [nc] 

可以訪問文件“ CSS”,“ JS”和“ index.php”。 其他請求將重定向到“拒絕”文件夾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM