开发者

Prevent hotlinking but allow specified images?

开发者 https://www.devze.com 2023-01-30 08:26 出处:网络
I\'m preventing hotlinking with this in htaccess: RewriteCond %{HTTP_REFERER} !^$ Rewri开发者_如何学GoteCond %{HTTP_REFERER} !^http://(www\\.)?mydomain\\.com [NC]

I'm preventing hotlinking with this in htaccess:

RewriteCond %{HTTP_REFERER} !^$
Rewri开发者_如何学GoteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(gif|jpe?g|png)$ - [F,NC,L]

However, I'd like to allow certain specified images to be hotlink-able, how do I do this? I can't find anything about it online.

Thanks, Colin


RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{REQUEST_URI}  !^images/allow-hotlink/.+\.(gif|jpe?g|png)$
RewriteRule \.(gif|jpe?g|png)$ - [F,NC,L]


you can add another rewrite condition like so:

RewriteCond %{REQUEST_URI}  !^whitelisted-directory/.*

but its more efficient and easier just to add one write rule that does nothing above and declare it at last like so:

RewriteRule ^(whitlistet-directory1|whitelisted-directory2) - [L]
0

精彩评论

暂无评论...
验证码 换一张
取 消