Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 3rd, 2001, 01:47 PM
djl's Avatar
djl djl is offline
PHPer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: London, UK.
Posts: 469 djl User rank is Private First Class (20 - 50 Reputation Level)djl User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 10 h 29 m
Reputation Power: 8
.htaccess and disallowing other sites my images

This relates to Apache because of the .htaccess
I wish to disallow other websites from linking to my images as it uses my bandwidh allowance up.

I looked around and found it could be done through .htaccess so i used the following commands in a .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteRule .*\.gif$ - [G]

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteRule .*\.jpg$ - [G]

Now all works correctly when i view the websites using my images, but the only problem is i get a 500 Internal Error.
Can anyone point the way to a different way of doing what need to do or possibly tell me whats wrong with the code above.

Thank you for any help received.

David

Reply With Quote
  #2  
Old June 4th, 2001, 02:22 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Don't use Block inlined-images at -> http://httpd.apache.org/docs/misc/rewriteguide.html

Use mine here and put it only in httpd.conf, not .htaccess. The rules can go within <VirtualHost> block, or preferably within <Directory>, just give it lowest priority like:
<VirtualHost *>
blah blah
..
rewrite lines here
</VirtualHost>
Or you can place it outside of <VirtualHost> and define it globally.

-- start here ---
# Enabling Rewite engine
RewriteEngine on

# Remove following 2 lines to enable rewrite log for debugging purpose only
# You can't use rewritelog directive in .htaccess
# You don't need these 2 lines when everything is working as expected
#RewriteLog "/full/path/to/rewrite_log"
#RewriteLogLevel 9

# If no http_referer, like requesting your image directly by typing to full URL to image, continue it to the next condition
RewriteCond %{HTTP_REFERER} ^$ [OR]

# If it has http_referer but it doesn't match http://www.domain.com or http://domain.com, stop now and apply the rule
# If you have other user at http://user.domain.com, change it to !^http://([www\.]*)domain\.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.*)domain\.com/.*$ [NC]

# Finally, [403] it for image.gif or image.GIF or IMAGe.jpg or image.JPeg or image.JPEG or the like
RewriteRule .*\.([gif|jpe?g]+)$ - [NC,F]

BE SURE TO CLEAN UP YOUR BROWSER CACHE when testing this because browsers almost always cache images.

BTW, I posted this stuff long time ago. If you performed a search in the forum, you would have gotten the rules already.

Last edited by freebsd : June 4th, 2001 at 02:27 AM.

Reply With Quote
  #3  
Old January 17th, 2002, 04:15 PM
edwinx edwinx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: vancouver, bc
Posts: 142 edwinx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 43 sec
Reputation Power: 9
Send a message via ICQ to edwinx
hi,

i just found this thread but wondering why not use the htaccess method?

what's the difference between the 2? does using httpd.conf allow for this rule to be applied to different domains whereas the htacces is done globally?

thanks
edwin
__________________
I know nothing

Reply With Quote
  #4  
Old January 18th, 2002, 12:51 AM
pippo's Avatar
pippo pippo is offline
A PAtCHy sErver
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Italy
Posts: 410 pippo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
httpd.conf is the apache configuration file (loaded when apache is launched on the server),
.htaccess is the so called "per-directory" configuration file.

Inside .htaccess can be placed a limited number of directives.

About perfomance is better to use httpd.conf,
but most of the time it is not accessible by "end-user".

For better and more detailed explanations than mine goto @

http://httpd.apache.org/docs/configuring.html
__________________
My article: mod_rewrite: No More Endless Loops!

Reply With Quote
  #5  
Old January 18th, 2002, 06:25 PM
edwinx edwinx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Location: vancouver, bc
Posts: 142 edwinx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 36 m 43 sec
Reputation Power: 9
Send a message via ICQ to edwinx
cool. thanks.

why is it better performance when using httpd.conf?

Reply With Quote
  #6  
Old January 18th, 2002, 06:29 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 18
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
>>why is it better performance when using httpd.conf?
Now, let me, the single straw man in this discussion, try to answer that
httpd.conf gets parsed only once by apache, and .htaccess is read every time request is made, therefore it is better to have that kind of global changes in .conf, but (un)fortunately hosts do not give access to httpd.conf and .htaccess is used.
__________________
And you know I mean that.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > .htaccess and disallowing other sites my images


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT