hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Image hosting htaccess Help!
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)
Forum Jump

Image hosting htaccess Help!

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 06-29-2008, 04:56 PM
Matth3wJL Matth3wJL is offline
Newbie
 
Join Date: Jan 2004
Posts: 24
Arrow

Image hosting htaccess Help!


My goal is to block hotlinking of fullsize images and display a image when they attempt it... but allow clickable thumbnails to be shown. For some reason the following isn't working... Any help would be greatly appreciated!

My htaccess looks like this:

RewriteEngine On
RewriteBase /images

#Allow if it's not from another website
RewriteCond %{HTTP_REFERER} ^$ [OR]
RewriteCond %{HTTP_REFERER} ^http://site.com/.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://www.site.com/.*$ [NC,OR]

#Allow if it's the hotlink.gif
RewriteCond %{REQUEST_FILENAME} hotlink.gif [NC,OR]

#Pass through thumbnails or hightlights as-is
RewriteCond %{REQUEST_URI} \.thumb.jpg$ [NC,OR]

#Return an anti-hotlink gif in place of any visual media
RewriteRule .*\.(jpe?g|gif|bmp|png)$ css/images/hotlink.gif [R,L,NC]

Thanks!

__________________


Reply With Quote


Sponsored Links
  #2  
Old 06-29-2008, 08:21 PM
foobic foobic is offline
Community Liaison 2.0
 
Join Date: Feb 2005
Location: Australia
Posts: 5,107
Your logic's out - you're listing all the conditions (using OR) that should allow images to show, and then redirecting these requests.

Instead you need to list all the conditions that should cause the redirect, reversing your existing rules, and use the implied AND which is default.

Try this:
Code:
RewriteEngine On

#Block it if the referrer is NOT blank
RewriteCond %{HTTP_REFERER} !^$

#AND if it's not from my own website
RewriteCond %{HTTP_REFERER} !^http://(www\.)?site.com/.*$

#AND if it's not a thumbnail
RewriteCond %{REQUEST_URI} !\.thumb.jpg$

#Return an anti-hotlink gif in place of any visual media
RewriteRule ^images/.*\.(jpe?g|gif|bmp|png)$ css/images/hotlink.gif [L,NC]

__________________
Chris

"Learn from the mistakes of others. You can never live long enough to make them all yourself." - Groucho Marx

Reply With Quote
  #3  
Old 07-01-2008, 07:16 AM
zuborg zuborg is offline
WHT Addict
 
Join Date: Jun 2008
Location: Ukraine
Posts: 141
Simply place big images into separate directory and put there antihotlinking .htaccess.
And leave thumbs without hotlink protection.
This will also decrease server load.

__________________
Know all about your site performance:
http://Site-Perf.com/

Reply With Quote
Sponsored Links
  #4  
Old 07-02-2008, 01:15 PM
Matth3wJL Matth3wJL is offline
Newbie
 
Join Date: Jan 2004
Posts: 24
Quote:
Originally Posted by foobic View Post
Your logic's out - you're listing all the conditions (using OR) that should allow images to show, and then redirecting these requests.

Instead you need to list all the conditions that should cause the redirect, reversing your existing rules, and use the implied AND which is default.

Try this:
Code:
RewriteEngine On

#Block it if the referrer is NOT blank
RewriteCond %{HTTP_REFERER} !^$

#AND if it's not from my own website
RewriteCond %{HTTP_REFERER} !^http://(www\.)?site.com/.*$

#AND if it's not a thumbnail
RewriteCond %{REQUEST_URI} !\.thumb.jpg$

#Return an anti-hotlink gif in place of any visual media
RewriteRule ^images/.*\.(jpe?g|gif|bmp|png)$ css/images/hotlink.gif [L,NC]

Doesn't seem to be working.. Thumb's are not showing.

Here is the example of the code the site gives you for the thumbnails:

Code:
<a href="http://www.site.com/viewer.php?file=u4w7iek3d5fzrxea9uhq.gif"><img src="http://www.site.com/images/u4w7iek3d5fzrxea9uhq_thumb.gif" border="0" alt="u4w7iek3d5fzrxea9uhq.gif" /></a>>

__________________


Reply With Quote
  #5  
Old 07-02-2008, 06:37 PM
foobic foobic is offline
Community Liaison 2.0
 
Join Date: Feb 2005
Location: Australia
Posts: 5,107
The condition allowing thumbnails (based on your original RewriteCond) assumes that the thumbnail filename ends in .thumb.jpg. To allow thumbnails like the one you have there replace the line with this:
Code:
#AND if it's not a thumbnail
RewriteCond %{REQUEST_URI} !_thumb\.(jpe?g|gif|bmp|png)$

__________________
Chris

"Learn from the mistakes of others. You can never live long enough to make them all yourself." - Groucho Marx

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Host Go Daddy Reveals New London Olympics Ads Created by Ad Agency Deutsch Web Hosting News 2012-07-26 14:16:28
Customer Feature: How EdgeCast Delivers One Billion Imgur Images Each Day Web Hosting News 2012-05-31 12:22:36
Web Host Webhostforasp.net Launches New Affiliate Program Web Hosting News 2012-01-16 14:31:12
Go Daddy Helping Customers Repair Compromised Sites Web Hosting News 2011-09-16 14:35:03
Web Host SoftLayer Launches Public Image Repository for Cloud Templates Web Hosting News 2011-06-08 14:56:19


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?