I am using wordpress and have some folders that users shouldn't see and browse. For this found solution - adding this line in .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. How can I do this?
You could create an index.php in those directories with following code:
header('HTTP/1.0 404 Not Found');
die('Page not found');
You can try with specific folder name like
Redirect 404 /folder1/
Redirect 404 /folder2/
In your root wordpress you can do this:
# 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.
ErrorDocument 403 /file_not_found.html
And file_not_found.html
should be in root folder.
您可以使用此:
DirectoryIndex /404.php
Found solution by just adding index.html file in those folders, and nothing in .htaccess file. Thanks everyone
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.