htaccess 中的 line 在做什么?

发布于 2024-10-26 22:31:28 字数 196 浏览 1 评论 0原文

我遇到了一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浴红衣 2024-11-02 22:31:28

请参阅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.

咋地 2024-11-02 22:31:28

RewriteRule .*\.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$ 匹配包含任意数量字符后跟句点和这些文件扩展名之一的任何文件名。

- 告诉 mod_rewrite 保持 URL 不变;显示 403 禁止页面时使用的技术细节。

[F,NC] F=禁止,NC=禁止;不区分大小写的匹配。

该规则很可能遵循(或应该遵循)一个或多个 RewriteCond,这是 RewriteRule 触发的条件。该规则的目的可能是阻止图像和其他文件被热链接。如果没有 RewriteCond,图像将始终被阻止。

一个精心设计的防止热链接的规则如下所示:

# Only apply the rule if the referrer isn't empty...
RewriteCond %{HTTP_REFERER} !^$
# ... and doesn't match your site.
RewriteCond %{HTTP_REFERER} !\.?mysite.com/$
# Also, only apply the rule for the specified file types.
RewriteRule \.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$ - [F,NC]

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 RewriteConds, 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 the RewriteCond, images will always be blocked.

A well designed rule for preventing hotlinking will look something like this:

# Only apply the rule if the referrer isn't empty...
RewriteCond %{HTTP_REFERER} !^$
# ... and doesn't match your site.
RewriteCond %{HTTP_REFERER} !\.?mysite.com/$
# Also, only apply the rule for the specified file types.
RewriteRule \.(jpg|jpeg|gif|png|bmp|pdf|exe|zip)$ - [F,NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文