问题
I would like to rewrite requests to directory secret
(http://example.com/secret) with .htaccess file to show always 404 Not Found
error. I'm using Apache 2.4.
It should work for those cases:
- /secret/treasure.php (all files and directories in that folder)
- /secret
- /secret/
- /secret?42
- /secret/?23
- /secret/.php → should result in 404 Not Found
- /secret/.htaccess → should result in 404 Not Found
My .htaccess rules block everything except the last two cases (I'm getting 403 error, but it should be 404):
Options -Indexes
RewriteEngine On
RewriteRule ^secret.*$ - [R=404,L]
I would like to rewrite requests /secret/.php
and /secret/.htaccess
to "404 Not Found error".
UPDATE: This is a bit hacky but seems to block everything
Options -Indexes
RewriteEngine On
RewriteRule ^secret.*$ - [R=404,L]
RewriteRule ^404_error$ - [R=404,L]
<FilesMatch "^\.">
order allow,deny
# 403 error
deny from all
# Rewrite 403 error to 404 error
# Must be an absolute path
ErrorDocument 403 /404_error
</FilesMatch>
来源:https://stackoverflow.com/questions/61198514/rewrite-requests-to-directory-with-htaccess-to-404-error