Forum Moderators: phranque
I've read the threads here on this forum about preventing remote linking to images on a website and I've tried to add a .htaccess file to my image dir and top dir, using ftp but the file does not show up in the remote server (in the ftp menu) and it does not work. Mode rewrite is enabled, according to my host and I can not acces the http.conf (I think that was the name) but I would really like to know how to prevent remote linking to my images as people keep on stealing them and my bandwidth (not all the host respond to my questions to do something about it).
I've tried this as the .htaccess file:
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mydomain.com/ [NC]
RewriteRule [^/]+.(gif¦jpg)$ - [F]
but it did not work.
I also would like to know how to redirect to my site if remote linking to an image is at hand but since I can't even fix this little .htaccess file (wonderful tip btw) I'll better wait with the redirect.
I hope anyone will look into this question again, I did read all the posts here from last year but withou result.
Thanks for any help!
[edited by: oilman at 5:44 am (utc) on Nov. 13, 2003]
There's a setting in your FTP client that is ignoring files that begin with a period.
Thats why you can't see the .htaccess file in the directory listing.
Start with a simple .htaccess file to check that it's even being parsed by apache.
make a directory, put this in (minus 'content' lines) and open it up in your browser.
---content of .htaccess file ---
AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthType Basic
AuthName "foo"<LIMIT GET POST>
require valid-user
</LIMIT>
---end content of .htaccess file ---
If it asks you for a password, your good.
Also, apache has to be compiled with mod_rewrite for this to work IIRC.
I noticed in your post that your regex isn't complete.
(the ^ and $ deliminate the beginning and end)
RewriteCond %{HTTP_REFERER}!^http://www.yourdomain.com/.*$ [NC]
RewriteRule [^/]+.(gif¦jpg)$ - [F] is what you should have I think.
-flashback
[edited by: flashback at 12:21 am (utc) on Nov. 13, 2003]
[edited by: oilman at 5:47 pm (utc) on Nov. 13, 2003]
No, they 'anchor' the beginning and the end - which is altogether a different thing from delimiting.
Ref: [etext.lib.virginia.edu...]
Try adding the Options and RewriteEngine directives. If this does not work, then contact your host.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.net [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteRule \.(gif¦jpg)$ - [F]
Jim
Make a new dir, and try to pull it up in your browser.
If you get "index of /foo" then indexes are on.
If you get forbidden, drop an index.html file (even an empty file) and it should pull that up.
Once you've determined that, *then* try your .htaccess file with the basic auth.
-flashback
#!/usr/bin/perl
print "Content-type: text/html\n\n";
my $server = `which httpd`; chomp $server;
my @modules = `$server -l`;
foreach my $ln (@modules) {print "$ln<BR>\n";}
upload that as test.pl and chmod it 755 using your ftp programs permissions thingy.
[edited by: flashback at 2:04 am (utc) on Nov. 13, 2003]
^ binds to the beginning of line and
$ binds to end of line
Mastering Regular Expressions taught me more in the first 40 pages than hacking perl for 4 years did.
I just don't talk about it as much as I use it.
And whats up with the pipe character having a crack in it?
Is that just font? or are they different?
--flashback
This forum software does two things you need to keep an eye on when posting regex: First it changes the pipe character to a "harmless" version, and second, it eats spaces preceding "!". You can force a space by posting two spaces, but there's no good work-around for the pipe.
More image hotlinking info on WebmasterWorld [google.com].
Jim
Now you just have to delete that 'test' .htaccess file with your ftp client (figure out how to see the files that begin with a period).
Then try that CGI I posted. (your looking for mod_rewrite.c)
Heres what mine shows:
Compiled-in modules:
http_core.c
mod_bandwidth.c
mod_env.c
mod_log_config.c
mod_log_agent.c
mod_log_referer.c
mod_mime.c
mod_negotiation.c
mod_status.c
mod_include.c
mod_autoindex.c
mod_dir.c
mod_cgi.c
mod_asis.c
mod_imap.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_access.c
mod_auth.c
mod_so.c
mod_setenvif.c
mod_fastcgi.c
mod_php4.c
Mode rewrite I see, so that must be good :-)