|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
.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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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! |
|
#5
|
|||
|
|||
|
cool. thanks.
why is it better performance when using httpd.conf? |
|
#6
|
||||
|
||||
|
>>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. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > .htaccess and disallowing other sites my images |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|