Hotlink protection for images only based on IP address

New to mod_rewrite? This is a good place to start.

Hotlink protection for images only based on IP address

Postby gary » Wed Jul 08, 2009 12:55 am

Code: Select all
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^00\.00\.00\.00$
RewriteRule ^.*$ http://domain.com


The code I am using is listed above.

I want to make some changes:
1. If a user hotlink images, it will show http://www.domain.com/images/nohotlink.jpg instead
gary
 
Posts: 7
Joined: Sun May 10, 2009 3:48 pm

Postby richardk » Wed Jul 08, 2009 8:39 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4$
RewriteCond %{REQUEST_URI} ^/images/nohotlink\.jpg$ [NC]
RewriteRule .\.(bmp|gif|jpe?g|png)$ /images/nohotlink.jpg [NC,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby gary » Wed Jul 08, 2009 12:25 pm

Tried it but it's not redirecting at all. I need it to protect other extensions too besides images except they should be redirected to different links.

1. Check IP address
2. If IP match, allow download (all files including images)
3. If IP does not match (all files except images), redirect to http://domain.com/noentry
4. If IP does not match (and is for images), redirect to http://domain.com/images/nohotlink.jpg

The .htaccess file and the nohotlink.jpg is on different subdomains.
gary
 
Posts: 7
Joined: Sun May 10, 2009 3:48 pm

Postby richardk » Wed Jul 08, 2009 2:25 pm

Code: Select all
RewriteCond %{REMOTE_ADDR} ^1\.2\.3\.4$
RewriteCond %{REQUEST_URI} ^/images/nohotlink\.jpg$ [NC]

should have been
Code: Select all
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteCond %{REQUEST_URI} !^/images/nohotlink\.jpg$ [NC]


Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteRule .\.(bmp|gif|jpe?g|png)$ http://www.example.com/images/nohotlink.jpg [R,L]

RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteRule .* http://www.example.com/noentry [R,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 114 guests

cron