问题原文
原帖链接 · Roman Simonyan · CC BY-SA 4.0
I am trying to block access to a specific folder and all of its content. I use methods suggested on the Internet, but they do not work.
This method does nothing:
RewriteRule ^folder_name/?$ - [F,L]
ErrorDocument 403 default
And this one brings internal server error:
<Directory "/folder_name/">
deny from all
</Directory>
What is wrong here?
My htaccess file looks like this:
RewriteEngine on
Options -Indexes
DirectoryIndex index.html
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
#rewrite rules for base URLs
RewriteRule ^([^/\.]+)[/]*$ $1\.html [QSA,L]
社区高分解答
原帖链接 · MrWhite · CC BY-SA 4.0
RewriteRule ^folder_name/?$ - [F,L]
This blocks access to the folder only; not its contents (because of the trailing end-of-string anchor). And since you have existing mod_rewrite directives, it will need to go near the top, before the existing directives.
Generally, you should have blocking directives first.
RewriteRule ^folder_name - [F]
: remaining directives follow
Alternatively, you create another .htaccess file inside the directory you want to block, with a single directive:
Require all denied
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
