what is line in the htaccess doing?
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 do开发者_JS百科ing
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
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)$
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 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]
精彩评论