ok so i have a couple of working codes
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://site.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://site.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.site.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.site.com$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp|mp3|wav)$ - [F,NC]
these would prevent hotlinking from your site hmm but when i viewed my so-called gallery which displays the jpg's it disappeared..is it possible to still use the images while using hotlink protection? i was kinda wondering
You can use this tool http://www.htaccesstools.com/hotlink-protection/
Use this generator to create a .htaccess file for hotlink protection of your images and pictures. Hotlink protection can save you lots of bandwidth by preventing other sites from displaying your images.
After you have created a .htaccess for hotlink protection, you can use the tool to test hotlink protection and make sure that you prevent hotlink.
Related
I am attempting to block hotlinked images from a specific site and re-route to an externally loaded/hosted image somewhere else.
I made some edits to my .htaccess file
Buy it also seems to block my OWN site/domain from my own images.. (even though I believe I am allowing it?)
I cant seem to get things to work with JUST blocking the external site...(without blocking my own site from my own images?)
I've tried so many lines... I cant make heads or tails on what is the issue that is blocking images from my own site.
Here is is my latest attempt
RewriteEngine On
#RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://myfakesite.net.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.myfakesite.net.*$ [NC]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?external-site\.com(/.*)*$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^https://(www\.)?external-site\.com(/.*)*$ [NC,OR]
RewriteRule .*\.(gif|jpg|jpeg|bmp|png)$ https://path-to-externally-hosted-image.jpg [R,NC]
*I erroneously though this would be much easier.. LOL
How can I block external-site.com and allow everything from mysite.net?
I blocked some sites in the file but they keep comming on my server and asking for images that slow down my server how i can add a rule for them so they will see big red sign STOP HOTLINKING
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://(www\.)?somesite\.pl [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?somesite\.pl [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?somesite\.pl [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?sklep.somesite\.eu [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]
Mate try the below ,
Following code will only allow the mentioned domain "alloweddomain.com" and block others from hot linking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?alloweddomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
The above code will allow "Blank Referrers"
What is Blank Referrers ?
Some visitors uses a personal firewall or antivirus program, that deletes the page referrer information sent by the web browser. Hotlink protection is based on this information. So if you choose not to allow blank referrers, you will block these users. You will also prevent people from directly accessing an image by typing in the URL in their browser.
Suppose if you don't want to allow "Blank Referrers" then use the following code mate
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?alloweddomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
Also if suppose you want to display a image like "STOP HOTLINKING" then use the below method
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?alloweddomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ mydomain.com/img/stop_hotlink.jpg [NC,R,L]
Above code will allow "Blank referrers" . To not allow, follow as mentioned in previous step again.
Note that :
In case of displaying image for "STOP HOTLINK" make sure the image is not hotlink protected or your server can go into an endless loop.
alloweddomain.com - The domain that you want to allow for hotlink
mydomain.com/img/stop_hotlink.jpg - URL for the "STOP HOTLINK" image
Update : [ Block Specific Domains ]
To stop hotlinking from specific outside domains only, such as blockurl1.com, blockurl2.com and blockurl3.com, but allow any other web site to hotlink images:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blockurl1\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blockurl2\.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?blockurl3\.com/ [NC]
RewriteCond %{REQUEST_URI} !blocked\.gif$ [NC]
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://example.com/blocked.gif [L]
You can add as many different domains as needed. Each RewriteCond line should end with the [NC,OR] code. NC means to ignore upper and lower case. OR means "Or Next", as in, match this domain or the next line that follows. The last domain listed omits the OR code since you want to stop matching domains after the last RewriteCond line.
The last line contains the URL "http://example.com/blocked.gif" which contains the image that will be displayed when the condition occurs.
You can display a 403 Forbidden error code instead of an image. Replace the last line of the previous examples with this line:
RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]
Hope this helped you mate!
My current htaccess prevents hot linking and direct download of files but its also blocking download from within the site. if the user is at http(s)?://(www\.)?domain.com/portal/WHATEVER then allow download, that's what i'm trying to achieve any advice?
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.com [NC]
RewriteRule \.(pdf|xls|xlsx|docx|doc)$ https://www.sub.domain.com/login.php [NC,R,L]
A user from a YouTube video has linked to my WordPress home page.
However, i want the incoming traffic to go to another page
I tried with .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} http\://www\.youtube\.com/watch\?v\=xxxxxxxxxx [NC]
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.*)$ http://www.domain.com/abc/post/ [R=302,L]
I am 100% that code is correct, yet it does not work. Are there any other alternatives besides the above code? Perhaps with PHP that I can use in the header or index file?
For one thing, youtube links are usually https so you should add a check for that:
RewriteCond %{HTTP_REFERER} https?\://www\.youtube\.com/watch\?v\=xxxxxxxxxx [NC]
The other thing is you need a space before the end of the video and the [NC] flag.
I have restricted hotlinking my files in using htaccess. But I need those files to be displayed in Google Doc Viewer.
In htaccess I allow Google Docs to hotlink my files, but it is not working. Please help me in this
Below is the code I used in my htaccess file
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomainname.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?docs.google.com [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(gif|png|jpg|doc|ppt|xls|pdf|html|htm|xlsx|docx|pptx|swf) [NC]
RewriteRule .*\.(gif|png|jpg|doc|ppt|xls|pdf|html|htm|xlsx|docx|pptx|swf)$ http://mydomainname.com/ [NC]
Using the referrer from https urls will probably not be very successful.
Note also that the remote in the googledocs are not fetched by the browser from your server, but from a server process at google.
I had the same problem and the trick I found was to allow a specific User-Agent:
RewriteCond %{HTTP_USER_AGENT} !(.*Feedfetcher-Google.*)
Of course it is easily spoofable, but in "normal usage" your hotlink protection will still work.
Oliver S is correct, but maybe the name of the user agent is changed now..
I tried
RewriteCond %{HTTP_USER_AGENT} !(.*Google.*)
And it worked perfectly