nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Apache stop image hotlink with .htaccess

This is a discussion on Apache stop image hotlink with .htaccess within the Web servers forums, part of the Mastering Servers category; i need a referer rewrite condition Domain somedomain.com is hosting from a server and other his sub-domains (sub1.somedomain.com etc) is ...


Go Back   nixCraft Linux Forum > Mastering Servers > Web servers

Linux answers from nixCraft.


Web servers Discussion on Apache, Nginx and Lighttpd HTTP/web server and configuration issues.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 28-05-2009, 05:40 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default Apache stop image hotlink with .htaccess

i need a referer rewrite condition

Domain somedomain.com is hosting from a server and other his sub-domains (sub1.somedomain.com etc) is hosting from other machines.

I need a RewriteCond for referer.

just wanted to restrict the request that comes except from internal domains and sub-domains.Mean Request will be denied if some one tried to fetch some stuffs like images from his own server.

I have the followings:

RewriteCond "%{HTTP_REFERER}" "!^http://somedomain.com/.*$" [NC]
RewriteRule "\.(jpg|gif|png|txt)$" [F]

what to do if i have the many sub-domains and different (live otherdomain.com) domains, i wanted to allow ?



if i am adding this:

RewriteCond "%{HTTP_REFERER}" "!^http://st1.somedomain.com/.*$" [NC]
RewriteCond "%{HTTP_REFERER}" "!^http://st2.somedomain.com/.*$" [NC]
RewriteCond "%{HTTP_REFERER}" "!^http://otherdomain.com/.*$" [NC]
#RewriteCond "%{HTTP_REFERER}" "!^http://%{HTTP_HOST}/.*$" [NC]
RewriteRule "\.(jpg|gif|png|txt)$" [F]

and using link on st1.somedomain.com

lynx http://st1.comedomain.com/mani/hh.php

then getting this error: message

Warning: file(http://somedomain.com/ma.txt) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not
Found in /var/www/html/hh.php on line 3
Warning: implode() [function.implode]: Invalid arguments passed in /var/www/html/hh.php on line 3


hh.php contains:

<?php

echo $html = implode('', file('http://somedomain.com/ma.txt'));

?>

Last edited by kasimani; 28-05-2009 at 05:50 PM.
Reply With Quote
  #2 (permalink)  
Old 01-06-2009, 04:07 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default Need more information ?

Quote:
Originally Posted by kasimani View Post
i need a referer rewrite condition

Domain somedomain.com is hosting from a server and other his sub-domains (sub1.somedomain.com etc) is hosting from other machines.

I need a RewriteCond for referer.

just wanted to restrict the request that comes except from internal domains and sub-domains.Mean Request will be denied if some one tried to fetch some stuffs like images from his own server.

I have the followings:

RewriteCond "%{HTTP_REFERER}" "!^http://somedomain.com/.*$" [NC]
RewriteRule "\.(jpg|gif|png|txt)$" [F]

what to do if i have the many sub-domains and different (live otherdomain.com) domains, i wanted to allow ?



if i am adding this:

RewriteCond "%{HTTP_REFERER}" "!^http://st1.somedomain.com/.*$" [NC]
RewriteCond "%{HTTP_REFERER}" "!^http://st2.somedomain.com/.*$" [NC]
RewriteCond "%{HTTP_REFERER}" "!^http://otherdomain.com/.*$" [NC]
#RewriteCond "%{HTTP_REFERER}" "!^http://%{HTTP_HOST}/.*$" [NC]
RewriteRule "\.(jpg|gif|png|txt)$" [F]

and using link on st1.somedomain.com

lynx http://st1.comedomain.com/mani/hh.php

then getting this error: message

Warning: file(http://somedomain.com/ma.txt) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not
Found in /var/www/html/hh.php on line 3
Warning: implode() [function.implode]: Invalid arguments passed in /var/www/html/hh.php on line 3


hh.php contains:

<?php

echo $html = implode('', file('http://somedomain.com/ma.txt'));

?>

Pl. let me if some other information also needed!
Reply With Quote
  #3 (permalink)  
Old 04-06-2009, 05:29 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

I'm sorry but I don't get your question... can you provide more info? Are you trying to restrict url access? If so you can restrict domains to certain ip address using LIMIT feature.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #4 (permalink)  
Old 04-06-2009, 05:09 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default

Thanks for attention !

I need a url condition, that will prevent Hot-Linking of Images and some text file from other websites.

I have many domains and sub-domains.
eg. domain1.com and it's so many sub-domains
domain2.com and so many sub-domain.... etc
etc...

Now i want to only allow my domains and their sub-domains to access these files (Images and text files.)

I did a little practice on this, and at some extent i achieved the goal.. but that is not a correct way to do this.... as i think.


RewriteCond %{HTTP_REFERER} !^http://(.+\.)?(domain1|domain2)\.([a-z.]+) [NC]
RewriteRule .*\.(jpe?g|gif|png|txt)$ - [F]

Is there any way, that Condition will read all the domains and sub-domains dynamically or from text files.

Regards
Manish Singh
Reply With Quote
  #5 (permalink)  
Old 04-06-2009, 08:15 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Yes, that is correct way to stop image hot linking. See
Apache prevent hot linking or leeching of images using mod_rewrite howto
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #6 (permalink)  
Old 12-06-2009, 04:20 PM
kasimani's Avatar
Senior Member
User
 
Join Date: Jul 2006
Location: India, Delhi
OS: CentOS, RedHat, Fedora, Ubuntu
Posts: 151
Thanks: 3
Thanked 1 Time in 1 Post
Rep Power: 4
kasimani is on a distinguished road
Send a message via Yahoo to kasimani
Default

my question is, is there any way that Rewrite Condition will read my all domains and sub-domains from a text file or from some other resources, that will fit in condition rather than using OR ( | ) condition in that

RewriteCond %{HTTP_REFERER} !^http://(.+\.)?(domain1|domain2)\.([a-z.]+) [NC]

i have so many domain by different names.

domain1.com
server.com
etc...

about 40-50 domains and sub-domains
Reply With Quote
  #7 (permalink)  
Old 12-06-2009, 08:38 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

No there is no text file or other file to include. You have to write complex task yourself. This is why they hired you to do all config work
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
apache image hotlink , stop apache hotlink , stop image hotlink


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Apache Redirect / to index.php using mod_rewrite .htaccess kasimani Web servers 3 30-01-2010 12:37 AM
Grant Start / Stop Apache Server Permission to Normal User tanweernoor Web servers 3 01-12-2008 04:13 AM
Lighttpd Wildcard based hotlink prevention Lamba Web servers 1 19-05-2008 01:23 PM
Lighttpd Hotlink Prevention Lizard King Web servers 1 02-05-2008 02:44 AM
Apache SYN Flood Attacks and how to stop / avoid them cbzee Web servers 1 21-12-2006 03:30 AM


All times are GMT +5.5. The time now is 09:04 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38