Discussion:
I don't get what is happening with this httpd.conf and mod_rewrite setup
(too old to reply)
Troels Jacob Ringsmose Feddersen
2012-04-30 13:31:12 UTC
Permalink
I'm setting up apache2 on a virtual ubuntu 12.04 server. I installed the
lamp-stack at server installation time. The server is going to host
mediawiki 1.8, and serve some files that I don't want people to be able
to hotlink. The following is a test of mod_rewrite and put in
/etc/apache2/httpd.conf:

RewriteEngine On
RewriteLog "/var/www/log/rewrite.log"
RewriteLogLevel 9
RewriteCond %{HTTP_REFERER} !(192\.168\.150\.130)
RewriteRule .*png$ - [F]


The virtual machine has 192.168.150.130 for IP and no domain name. I'm
trying to prevent downloading any png file, without the referer being my
server. For some reason this doesn't work. I know that the file is used
by the server, because if I mug up the path to my log file, the server
won't start, and the apache log states that the file couldn't be found.
The weird part is, that the log isn't touched (and the apache user is
the owner and has write access) and I can get download png files without
a referer. So this leaves me to think, that the either the RewriteCond
line i messed up, or something prevents it from being used.

I'd be grateful for any ideas
--
regards
Troels
Troels Jacob Ringsmose Feddersen
2012-05-01 11:09:36 UTC
Permalink
So I figured it out, with some help in dk.edb.internet.software.apache,
see 4f9f9934$0$35275$c3e8da3$***@news.astraweb.com if you happen to
speak danish.

My httpd.conf was botched. Of course I can't let this stand alone

RewriteEngine On
RewriteLog "/var/www/log/rewrite.log"
RewriteLogLevel 9
RewriteCond %{HTTP_REFERER} !(192\.168\.150\.130)
RewriteRule .*png$ - [F]

I had to give apache a little more info:

RewriteLog "/var/www/log/rewrite.log"
RewriteLogLevel 9
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
RewriteEngine On
RewriteCond %{HTTP_REFERER} !(192\.168\.150\.130)
RewriteRule .*png$ - [F]
</Directory>

This is the httpd.conf that does what I was trying to do in the first
place: Block requests for png files without the correct referer.
--
mvh | regards
Troels
Loading...