簡體   English   中英

.htaccess全部拒絕,重定向到404頁面,除了2個文件

[英].htaccess deny from all, redirect to 404 page and except for 2 files

我如何設置一個.htaccess來拒絕include/文件夾中的任何.php文件訪問,並在發生403、404和500時將用戶重定向到public_html/ (根)目錄中的error頁面,但除了2個被稱為文件index.phpkey.php嗎?

目前,這是我所擁有的:

<Files "^*\.php$">
order allow,deny
deny from all
</Files>
ErrorDocument 403 /error.html
ErrorDocument 404 /error.html
ErrorDocument 500 /error.html

<FilesMatch "^(index|key)\.php$">
Allow from all
</FilesMatch>

但這不能正常工作,只有<FilesMatch "^(index|key)\\.php$">可以正常工作。

謝謝!

如果不是這種情況,則應將.htaccess文件放入include/目錄。 我認為您對Files標簽使用了FilesMatch語法。

<FilesMatch "^.*\.php$>
    order deny,allow # Deny here, allow later.
    deny from all
</Files>

<FilesMatch "^(index|key)\.php$">
    allow from all  # Allow here.
</Files>

然后,在您的根目錄( public_html/ )中,可以使用:

ErrorDocument 403 /error.html
# Try ../error.html if you put this line in include/.htaccess

確保error.html的路徑有效。 如果您看到類似“ 在查找錯誤文檔時遇到錯誤 ”之類的信息,則它是錯誤的(嘗試從Linux根目錄獲取絕對路徑嗎?)

暫無
暫無

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

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