htaccess 中的 line 在做什么?
我遇到了一个带有 403 禁止的 img 文件夹的问题,并发现问题是由这一行引起的....这是在做什么
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$ - [F,NC]
以及为什么它会在包含图像的 /something/img 文件夹上导致 403 禁止
I was having problems with an img folder having a 403 forbidden and come to find out the issue was caused by this line....what is this doing
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$ - [F,NC]
and why would it cause a 403 forbidden on a /something/img folder that had images
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅http://httpd.apache.org/docs/1.3/mod/mod_rewrite。 html
F = 禁止,强制所有以这些扩展名之一结尾的 URL 出现 403 错误。
NC = 无大小写(即也适用于 .GIF 等)。
See http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
F = forbidden, forces 403 errors on all URLs ending with one of these extensions.
NC = no case (ie. also works on .GIF for example.
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$
匹配包含任意数量字符后跟句点和这些文件扩展名之一的任何文件名。-
告诉 mod_rewrite 保持 URL 不变;显示 403 禁止页面时使用的技术细节。[F,NC]
F=禁止,NC=禁止;不区分大小写的匹配。该规则很可能遵循(或应该遵循)一个或多个
RewriteCond
,这是 RewriteRule 触发的条件。该规则的目的可能是阻止图像和其他文件被热链接。如果没有RewriteCond
,图像将始终被阻止。一个精心设计的防止热链接的规则如下所示:
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$
Matches any file names containing any number of characters followed by a period and one of those file extionsions.-
Tells mod_rewrite to keep the URL untouched; a technicality emplofed when showing a 403 forbidden page.[F,NC]
F=Forbidden, NC=No case; a case-insensitive match.Most likely this rule follows (or is supposed to follow) one or more
RewriteCond
s, which are conditions under which the RewriteRule will trigger. The intention of the rule was probably to block images and other files from being hotlinked. Without theRewriteCond
, images will always be blocked.A well designed rule for preventing hotlinking will look something like this: