PDA

View Full Version : Will this .htaccess work?


dantra
11-19-2006, 07:48 AM
After trying many different ways of preventing hot-linking to my images, I finally got one to work:

RewriteEngine on
# Prevent hot-linking
# Allow linking from my own site
RewriteCond %{HTTP_REFERER} !^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com$ [NC]
# But not allow hot-linking to any images in the image_folder
RewriteCond %{REQUEST_URI} !^/image_folder/.*$ [NC]
# Re-direct any links to image files to another site
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.site-to-redirect-to.com/ [R,NC,L]

I’m trying to apply the Rewrite rule in the .htaccess to affect the rest of my site, not just the home page. Will this work?

RewriteEngine on
# Prevent hot-linking
# Allow linking from my own site
RewriteCond %{HTTP_REFERER} !^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com/page2/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com/page2$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/page2/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/page2$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com/page3/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://mysite.com/page3$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/page3/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/page3$ [NC]
etc…
# But not allow hot-linking to any images in the image_folder
RewriteCond %{REQUEST_URI} !^/image_folder/.*$ [NC]
RewriteCond %{REQUEST_URI} !^/image_folder2/.*$ [NC]
RewriteCond %{REQUEST_URI} !^/image_folder3/.*$ [NC]
etc…
# Re-direct any links to image files to another site
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ http://www.site-to-redirect-to.com/ [R,NC,L]

dantra
11-21-2006, 06:07 PM
Nevermind, I figured it out.:thumbsup: