Matt Elhotiby
Matt Elhotiby

Reputation: 44086

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 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

Upvotes: 0

Views: 259

Answers (2)

nitro2k01
nitro2k01

Reputation: 7745

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]

Upvotes: 2

PhiLho
PhiLho

Reputation: 41162

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.

Upvotes: 3

Related Questions