簡體   English   中英

.htaccess - 拒絕除 index.php 和當前目錄之外的所有內容。/

[英].htaccess - Deny from all except index.php and current directory ./

.htaccess

“拒絕所有”除 index.php 和當前目錄之外的所有文件。/

大家好,我正在嘗試一個必須工作但我不知道該怎么做的愚蠢事情。

通過這種方式,我可以為除 index.php 頁面(圖像和 CSS 之外的所有文件)的用戶提供 403 錯誤

Order Deny,Allow
Deny from all
Allow from 127.0.0.1
<Files /index.php>
    Order Allow,Deny
    Allow from all
</Files>

但我還想將當前目錄 [./] 添加到允許的搜索中

怎么做?

因為如果我從瀏覽器搜索 THIS URL --> https://hostname.com/403dir/它會給我 403 錯誤,我不想要它。

TNKS

使用您顯示的示例,您能否嘗試以下操作。 確保您的 htaccess 文件位於根路徑中(除了 403dir 路徑不在 403dir 內)。

請確保在測試您的 URL 之前清除您的瀏覽器緩存。

RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/403dir/?$ [NC]
RewriteCond %{REQUEST_URI} !index\.php$ [NC]
RewriteRule ^ - [F,L]


或按如下方式使用單個條件本身,請確保您一次使用上述解決方案或以下解決方案。

RewriteEngine ON
RewriteCond %{REQUEST_URI} !(^/403dir|index\.php$) [NC]
RewriteRule ^ - [F,L]

暫無
暫無

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

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