httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kurtis Rader <kra...@skepticism.us>
Subject Re: [users@httpd] mod_rewrite
Date Mon, 12 Oct 2015 23:40:07 GMT
On Mon, Oct 12, 2015 at 3:27 PM, Earl Terwilliger <earl@micpc.com> wrote:

> I am a bit confused about the mod_rewrite documentation. It shows this
> rule to block hotlinking:
>
> RewriteCond "%{HTTP_REFERER}" "!^$"
> RewriteCond "%{HTTP_REFERER}" "!www.example.com" [NC]
> RewriteRule "\.(gif|jpg|png)$"    "-"   [F,NC]
>

That's not what I see at
http://httpd.apache.org/docs/current/mod/mod_rewrite.html but that doesn't
really matter. I mention it only to point out that you really should be
specific when stating what documentation you are reading. In this case a
URL would have been a good idea.

however, I'd think a better rule would be:
>
> RewriteCond "%{HTTP_REFERER}" "^$" [OR]
> RewriteCond "%{HTTP_REFERER}" "!(www\.)?example.com/.*$" [OR,NC]
> RewriteRule "\.(gif|jpg|png)$"    "-"   [F,NC]
>
> if I want to block anyone manually typing in a link (no referer) +
> hotlinking (probably has a referer). Do i need the [OR] on the 1st
> RewriteCond and not the 2nd one? It seems to work with OR on both
> conditions.
>

The [OR] on the second RewriteCond does nothing since it isn't followed by
another RewriteCond. You also don't need the first RewriteCond since by
definition an empty HTTP_REFERER won't match pattern.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

Mime
View raw message