我只想在.well-known directory 中將此檔案列入白名單。
我的 htaccess 檔案
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
我的嘗試
<Files .well-known/security.txt>
Allow from all
Satisfy Any
</Files>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^(public|.well-known/security.txt)
RewriteRule ^(.*)$ public/$1 [L]
結論 !我只想將.well-known 目錄中的security.txt檔案列入白名單
uj5u.com熱心網友回復:
RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/$1 [L]
這個條件是錯誤的,因為REQUEST_URI服務器變數總是以斜杠開頭,所以運算式!^public總是成功的。
(由此我假設您必須.htaccess在子目錄中有另一個檔案/public,否則您將獲得重寫回圈。)
一旦您意識到這一點,您就可以按照您嘗試過的方式修改規則。例如:
RewriteCond %{REQUEST_URI} !^/(public|\.well-known/security\.txt$)
RewriteRule ^(.*)$ public/$1 [L]
但是,您的其他規則會阻止對以點開頭的物理檔案/目錄的所有請求,因此該請求仍將被阻止(403 Forbidden)。這條規則對于其他請求也是錯誤的(它需要在重寫到/public子目錄之前)。
您最好在檔案開頭將例外作為單獨的規則。例如,請嘗試以下操作:
Options -Indexes
RewriteEngine on
# Prevent further processing for special files
RewriteRule ^\.well-known/security\.txt$ - [L]
# Block access to all dot-files
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule (^|/)\. - [F]
# Rewrite request to "/public" subdirectory
RewriteCond %{REQUEST_URI} !^/public
RewriteRule (.*) public/$1 [L]
該<IfModule>規則的包裝是多余的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/521857.html
