Avoid Hot-Linking by .htaccess

zelvmoney

New member
Nov 4, 2008
64
1
0
Avoid Hot-Linking through .htaccess

Hi everybody!

I want to avoid hot-linking and I know I should add this to my .htaccess:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

My .htaceess is:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

My question is: Where exactly should I put the "avoid hot-linking" code? Can somebody put it here how does my .htacees file should became? Thanks in advance
 


It´s working... I hope my .htaccess is ok this way...


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
</IfModule>

# END WordPress
 
It´s working... I hope my .htaccess is ok this way...


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
</IfModule>

# END WordPress
Actually it's not working!! Can somebody explain me how to do it? Thx in advance
 
Code:
RewriteEngine On
                    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
                    RewriteCond %{HTTP_REFERER} !^$
                    RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]
 
Code:
RewriteEngine On
                    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
                    RewriteCond %{HTTP_REFERER} !^$
                    RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]
Hi! Thaks for your answer but... if you read my first post I know the right code but I don´t want to change my .htaccess, I want to add this code to my .htaccess and I don´t know how to do it the right way...
Thanks again
 
Just combine them, it's not that hard. It should look like this.

RewriteEngine On
RewriteBase /

# Prevent hotlinking images
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?mysite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
# END hotlinking prevention

# Begin Wordpress rewrites
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress