Rewrite and hotlink protection

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

Postby ng » Sat Sep 26, 2009 5:44 pm

hey i need blocked folder where are my images... similiar like here..
example: image on http://www.freepicload.com/view.php?ima ... 10af50.png

and if any user will copy this pic (http://www.freepicload.com/upload/e14cd ... 10af50.png) so wont doesnt work..probably i will need rewrite folders ....i need htaccess code, thanks very much :)
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Postby ng » Sat Sep 26, 2009 5:46 pm

and another i want block hotlink from my web, only viewer allowed ...no direct link!
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Postby richardk » Sun Sep 27, 2009 10:47 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Hotlink protection.
RewriteCond %{HTTP_REFERER} ^(http://(www\.)?example\.com(/.*)?)?$ [NC]
RewriteRule ^.+\.(gif|jpe?g|bmp|png)$ - [F,L]

# /upload/file to /view.php?image=file
RewriteRule ^upload/([^/]+)$ /view.php?image=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ng » Sun Sep 27, 2009 12:02 pm

sí now work but bad..now is block this for ex: http://www.freepicload.com/upload/e14cd ... 10af50.png thanks richardk

but i have problem, doesnt work normal viewer for ex: http://www.freepicload.com/view.php?ima ... af50.png... is writing only name of file but no completly images..:(
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Postby richardk » Sun Sep 27, 2009 2:20 pm

Try this mod_rewrite test
The FAQ wrote:How to check if mod_rewrite is enabled.

Put the following mod_rewrite in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule modrewrite http://www.modrewrite.com/? [NC,R,L]

Now go to http://example.com/modrewrite (where example.com is your domain or IP address). If you are redirected to modrewrite.com, mod_rewrite should be working OK.

Do you get redirected?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ng » Sun Sep 27, 2009 4:14 pm

yes mod_rewrite is enabled, now its working but i have problem again.. direct url is blocked but doesnt work image thumbnail viewer..:( show for me only this http://i34.tinypic.com/1616kh.jpg ... without image thumb.. :( thanks for your answer :)
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Postby ng » Sun Sep 27, 2009 4:28 pm

edit: thumbs images are in folder "thumbs" and normal images are in folder "images" and normal images are okay, viewer is enable and direct link is disable for this ty richardk but is wierd that also folder "thumbs" with my thumbs images is disable it must be enable for me, cus i need images preview in small size :) on forum etc..
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Postby richardk » Mon Sep 28, 2009 2:11 pm

Try adding
Code: Select all
RewriteCond %{REQUEST_URI} !^/thumbs(/.*)?$ [NC]

after
Code: Select all
RewriteCond %{HTTP_REFERER} ^(http://(www\.)?example\.com(/.*)?)?$ [NC]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby ng » Tue Sep 29, 2009 8:13 am

richardk wrote:Try adding
Code: Select all
RewriteCond %{REQUEST_URI} !^/thumbs(/.*)?$ [NC]

after
Code: Select all
RewriteCond %{HTTP_REFERER} ^(http://(www\.)?example\.com(/.*)?)?$ [NC]


does not work richardk :(
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Postby ng » Tue Sep 29, 2009 1:18 pm

richardk maybe will better rewrite folder only... for example: i have

http://www.hosting.com/show/01.jpg (viewer with normal page)

and if user get direct url

http://www.hosting.com/images/01.jpg (direct url)

so automatically it will rewrite to back http://www.hosting.com/show/01.jpg


and here is live site which has the some system http://www.stooorage.com/
http://www.stooorage.com/show/199/261029_balon.jpg
http://www.stooorage.com/images/199/261029_balon.jpg

and result is only http://www.stooorage.com/show/199/261029_balon.jpg

thanks very much richardk :)
ng
 
Posts: 13
Joined: Sat Sep 26, 2009 5:34 pm

Next

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 29 guests

cron