简体   繁体   English

如何将文件夹浏览重定向到错误404页面

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

I am using wordpress and have some folders that users shouldn't see and browse. 我正在使用wordpress,并且有一些用户不应该查看和浏览的文件夹。 For this found solution - adding this line in .htaccess 对于此找到的解决方案-在.htaccess中添加此行

Options All -Indexes or Options -Indexes

But it redirects to 403 - FORBIDDEN page of server, I need to redirect to my site's error 404 page. 但是它重定向到服务器的403-FORBIDDEN页面,我需要重定向到我的网站的错误404页面。 How can I do this? 我怎样才能做到这一点?

You could create an index.php in those directories with following code: 您可以使用以下代码在这些目录中创建index.php:

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

You can try with specific folder name like 您可以尝试使用特定的文件夹名称,例如

Redirect 404 /folder1/ 重定向404 /文件夹1 /

Redirect 404 /folder2/ 重定向404 /文件夹2 /

In your root wordpress you can do this: 在您的root wordpress中,您可以执行以下操作:

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

# disables directory listing
Options -Indexes

Add this in your .htaccess file which is in root of your website. 将此添加到网站根目录中的.htaccess文件中。

ErrorDocument 403 /file_not_found.html

And file_not_found.html should be in root folder. 并且file_not_found.html应该在根文件夹中。

您可以使用此:

DirectoryIndex /404.php

Found solution by just adding index.html file in those folders, and nothing in .htaccess file. 通过在这些文件夹中添加index.html文件,而不在.htaccess文件中添加任何内容来找到解决方案。 Thanks everyone 感谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM