簡體   English   中英

如何將文件夾瀏覽重定向到錯誤404頁面

[英]how to redirect folders browsing to error 404 page

我正在使用wordpress,並且有一些用戶不應該查看和瀏覽的文件夾。 對於此找到的解決方案-在.htaccess中添加此行

Options All -Indexes or Options -Indexes

但是它重定向到服務器的403-FORBIDDEN頁面,我需要重定向到我的網站的錯誤404頁面。 我怎樣才能做到這一點?

您可以使用以下代碼在這些目錄中創建index.php:

header('HTTP/1.0 404 Not Found');
die('Page not found');

您可以嘗試使用特定的文件夾名稱,例如

重定向404 /文件夾1 /

重定向404 /文件夾2 /

在您的root wordpress中,您可以執行以下操作:

# handles 403 (forbidden) status as 404 (not found)
ErrorDocument 403 /index.php?error=404

# disables directory listing
Options -Indexes

將此添加到網站根目錄中的.htaccess文件中。

ErrorDocument 403 /file_not_found.html

並且file_not_found.html應該在根文件夾中。

您可以使用此:

DirectoryIndex /404.php

通過在這些文件夾中添加index.html文件,而不在.htaccess文件中添加任何內容來找到解決方案。 感謝大家

暫無
暫無

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

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