I'll get straight to it. I have this code in my .htaccess file to prevent hotlinking, see below:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://mywebsite.ca/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mywebsite.ca$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.ca/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mywebsite.ca$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
but I will have a few .jpg images up for banner exchange between sites and I don't know how to write the rule to allow hotlinking for just one folder. In this case the one folder will be root/image/links/
What changes in the rewrite conditions do I need to make to allow hotlinking for this one folder?
Thanks for your anticipated help everyone.
You can use
RewriteCond %{REQUEST_URI} !^/image/links/
as an additional condition.
Related
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]
I know the basics for writing an .htaccess that handle a maintenance mode page.
I don't want to use a plugin, as I need to replace the whole WP site while in maintenance mode.
I've tried to add additional rules to allows access to WP Back-End, only for specific IPs.
I've tried several attempts and eventually got very close to what I need.
However, I also want the white-listed IP(s) be able to see the front-end site, without being redirected to the maintenance page, but I'm stuck there.
Here's my current .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/images [OR]
RewriteCond %{REQUEST_URI} ^/wp-admin/.* [OR]
RewriteCond %{REQUEST_URI} ^/wp-content/.* [OR]
RewriteRule .+ - [L]
RewriteCond %{REMOTE_ADDR} !^93\.62\.93\.79
RewriteCond %{REQUEST_URI} !^/maintenance-mode\.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance-mode.html [R=302,L]
What I'm supposed to add/change?
Did you found a solution? I don't tested it with WP but this worked for me for another CMS.
Options +FollowSymLinks
RewriteEngine On
# exclude file (otherwise infinity loop)
RewriteCond %{REQUEST_URI} !^/under-construction/maintenance\.php$
# exclude images and css
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css) [NC]
# If it's not your IP address
RewriteCond %{REMOTE_HOST} !^111\.222\.333\.444$
# Redirect /abc to example.com/abc.
RewriteRule ^(.*)$ http://www.domain.com/under-construction/maintenance.php [R=307,L]
Perhaps it will help you.
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]
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]
I'm preventing hotlinking with this in htaccess:
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(gif|jpe?g|png)$ - [F,NC,L]
However, I'd like to allow certain specified images to be hotlink-able, how do I do this?
I can't find anything about it online.
Thanks,
Colin
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{REQUEST_URI} !^images/allow-hotlink/.+\.(gif|jpe?g|png)$
RewriteRule \.(gif|jpe?g|png)$ - [F,NC,L]
you can add another rewrite condition like so:
RewriteCond %{REQUEST_URI} !^whitelisted-directory/.*
but its more efficient and easier just to add one write rule that does nothing above and declare it at last like so:
RewriteRule ^(whitlistet-directory1|whitelisted-directory2) - [L]