Strange hotlink protection issues - .htaccess - .htaccess

I used the rules that should work, and have worked in the past but every variation I try it continues to serve a the image (clearing cache each time). Other rules like URL rewrites work fine.
I would provide a copy of the error logs but I can't seem to gain access to this through FTP, neither can the person running the server droplet.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(sub\.)?example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
I know this seems like it should all be working, everyone says the codes are correct. Yet for the past few weeks I have been trying find solutions. I'm positive there is something else going on that is not related to the code, I just need help finding it as I'm not too experienced working extensively with htaccess.
Full htaccess:
ErrorDocument 404 /404.php
AuthType Basic
AuthName "Password Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?dev.mangazing\.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

Is this what you're looking for?
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?sub.example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
EDIT
Please try to replace your rewrite rule line
Replace:
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
With:
RewriteRule \.(jpg|jpeg|png|gif)$ http://icons.iconarchive.com/icons/tatice/cristal-intense/256/Ad-Aware-icon.png [NC,R,L]
Your code will look like:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?sub.example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://icons.iconarchive.com/icons/tatice/cristal-intense/256/Ad-Aware-icon.png [NC,R,L]
Or
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?dev.mangazing\.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://icons.iconarchive.com/icons/tatice/cristal-intense/256/Ad-Aware-icon.png [NC,R,L]
and visit 1 of your image urls, I hope this is working for you.. remember to upload a replacement picture to a server and change replacement URL in the new rewrite rule, this can be done with a transparent 1 pixel image (Not a html/php etc document, it must be an image file!) free hosted at google pages or any other webhosting service you like..
Edit 2
Please try with <IfModule mod_rewrite.c>:
<IfModule mod_rewrite.c>
RewriteEngine on
#Your other anti hotlink commands here...
</IfModule>
More methodes to protect image hotlinking: creating the ultimate .htaccess anti hotlinking strategy

Related

What changes should I have to implement in my .htaccess if I want to allow specific URL but prevent on all others?

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?site1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?site2\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^$
RewriteRule \.(jpg|jpeg|png|gif|js|css)$ - [NC,F,L]
The above code is doing the opposite for me. I want to a site1 and site2 but prevent all others.
You should have your .htaccess rules file in following manner. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine on
RewriteCond %{HTTP_HOST} ! ^https?://(?:www\.)?(?:site1|site2)\.com$ [NC]
RewriteRule \.(jpg|jpeg|png|gif|js|css)$ - [NC,F,L]

Referrer not blocked by htaccess

I am trying to help a black funeral home stop harassment by a racist site. One request they made was that I prevent direct linking from the racist site to theirs.
The following is the whole .htaccess
When I go to the harassing site (name not listed below as it contains racial slurs) and click one of their links to the funeral home I am never blocked.
What did I do wrong?
ErrorDocument 404 /index.php
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} racistsitenamehere\.net [NC]
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
RewriteEngine on
RewriteBase /
RewriteRule ^([^/\.]+)/?$ /page.php?page=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /page.php?page=$1&sub=$2 [L]
# block semalt
order allow,deny
deny from 85.58.23.115
deny from 177.21.203.170
allow from all
You're missing an [OR], since the referer can't be BOTH (e.g. AND) of those, you want one or the other to be true:
RewriteCond %{HTTP_REFERER} racistsitenamehere\.net [NC,OR]
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F,L]
Also wouldn't hurt to have an L flag in there.

How to exclude certain filenames from being Hotlinked Blocked in .htaccess

I've currently got the following in my .htaccess of my photo folder.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?siteabc.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?sitexyz.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://example.com/images/bandwidth.png [NC,R,L]
This blocks all not allowed domains from hotlinking our photo files and displays the http://example.com/images/bandwidth.png in it's place.
However, what I would like to do is to allow sites to be able to hotlinked our thumbnails. The thumbnail images have this sort of filename format
filenameabc_100_cw100_ch100_thumb.jpg
filenameabc_100_cw100_ch100_thumb.png
filenamexyz123_100_cw100_ch100_thumb.png
eg the filenames all end with _thumb.ext
So what I would like to do is to modify the above .htaccess to globally block all access with the exception of the filenames ending in thumb eg *_thumb.jpg or *_thumb.png
I don't have the first idea about how to write such a rule.
If anyone has any ideas I would be most grateful.
Modifying the rule-set in the question:
You may try this:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?siteabc.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?sitexyz.com [NC]
# Add this other exception
RewriteCond %{REQUEST_URI} !_thumb\. [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://example.com/images/bandwidth.png [NC,R,L]

htaccess hotlink protection

So I'm trying to protect FLV files using htaccess.
Basically I want to block direct access to the .flv (so blank referrer) and block hotlinking from any website that isn't my own.
I'm doing this from a WordPress install but it's not on the root, it's in a subdirectory. so mydomain.com/test/videos/
I've tried the following code but I am still able to type a direct filename of the flv and chrome will download the file, so it isn't working:
RewriteEngine on
RewriteBase /test/videos/
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.co.uk(/)?.*$ [NC]
RewriteRule \.(flv)$ templates/images/logo.jpg [L,NC]
Any ideas where this is going wrong? it doesn't return a server error.
Try this one:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mydomain.co.uk/test/videos [NC]
RewriteRule \.(flv)$ - [NC,F,L]

Domain based redirect to different PHP files via htaccess

Domain based redirect to different PHP files via htaccess
Hello there.
Here's the thing:
I have two domains here [http://www.myproject.com and
[http://www.myproject.com.br .. In my root folder i have all the stuff for
my projects including two "indexes": "index-en.php" for english and
"index.php" for portuguese.
Can i have some trick in htaccess that redirect my users to one
of these files depending on domain? .. something like:
[http://www.myproject.com [OR]
[http://myproject.com redirect to [http://www.myproject.com/index-en.php
and
[http://www.myproject.com.br [OR] [http://myproject.com.br redirect to
[http://www.myproject.com.br/index.php
??
Sorry if this is a stupid question but im almost crazy looking for tutorials over
the internet and i cant get something that works or some response if this is possible or just a stupid question .. Can someone please give me some direction?
Maybe some solution with a conditional directoryIndex (I dont know if that's possible).
thanks a lot
Actually i have this in my .htaccess:
ErrorDocument 404 /404.php
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^myproject.com$ [NC]
RewriteRule ^(.*)$ http://www.myproject.com/index-en.php [R=301,L]
RewriteCond %{HTTP_HOST} ^myproject.com.br$ [NC]
RewriteRule ^(.*)$ http://www.myproject.com.br/ [R=301,L]
</IfModule>
This just does the "non www to www" - that works correctly
This should do what you want. The RewriteCond trickery is probably a bit overkill here, but it does make adding extra languages easier:
ErrorDocument 404 /404.php
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}/index.php \.com\.br/(index.php)$ [NC,OR]
RewriteCond %{HTTP_HOST}/index-en.php \.com/(index-en.php)$ [NC]
RewriteRule ^ %1
RewriteCond %{HTTP_HOST} myproject\.com$
RewriteRule ^/$ /index-en.php
RewriteCond %{HTTP_HOST} myproject\.com\.br$
RewriteRule ^/$ /index.php

Resources