Forum Moderators: phranque
This is what I have: I want to know if there is way to make it so that it works on all of goodomain.com for other folders such as goodomain.com/2/ gooddomain.com/3/ etc. Right now it only works from main domain. People can still hotlink other directories within goodomain.com.
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?gooddomain.com(/)?.*$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp)$ [stopspammers.com...] [R,NC]
I don't want to have to keep adding new directories to it each time. Isn't there a way I hotlink protect all directories within domain?
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?goodref.com(/)?.*$ [NC]
RewriteRule .*\.(gif¦jpg¦jpeg¦bmp¦wmv¦wma¦png¦mpeg¦mpg¦avi¦mp4)$ [spamforspammers.com...] [R,NC]
How does this look? Is it efficiently coded, or is there a better code?
You have some unnecessary patterns in your regular expressions, which can simply be omitted for the sake of efficiency without changing the function. Specifically, leading and traillng ".*" patterns are redundant and don't do anything.
Also, redirecting an image request to an html (or html-like) page won't work -- browsers can't handle it. I suggest you simply return a 403-Forbidden response.
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(www\.)?goodref\.com [NC]
RewriteRule \.(gif¦jpe?g¦bmp¦wm[av]¦png¦mpe?g¦avi¦mp4)$ - [NC,F]
I'm putting all my ErrorDocument stuff in my <VirtualHost> directive in Apache. It handles all of site then and will do subdirectories as well.
Any chance that I can throw in the mod_rewrite code in <Virtualhost> area to do the same instead of using .htaccess files?
Yes, like all Apache directives, each mod_rewrite directive states what context it is available in. Check the documentation [httpd.apache.org] for each directive you wish to use.
Jim