Possible to prevent hotlinking when apache server has no domain name?

sogosu asked:

I have a LAMP + WordPress server that I access with the IP address only. I don’t plan on getting a domain name for the server.

I want to know if it is possible to prevent hotlinking of resources if my server doesn’t have a domain name?

Right now I configured my .htaccess like below, but it doesn’t seem to be working.

IndexIgnore */*
php_flag zlib.output_compression Off

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(.+.)? [NC]
RewriteRule \.(zip|gif|jpg|js|css|png)$ - [F]

Edit to add for @JennyD:
I checked the access.log and couldn’t see a referrer.
My apache2.conf defines a custom log format called ‘combined’:

LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

In my sites-enabled, the ‘combined’ access log format is used by the directive:

CustomLog ${APACHE_LOG_DIR}/access.log combined

This is what my access.log is showing: - - [04/Jun/2013:11:19:02 +0200] "GET /wordpress/wp-includes/images/admin-bar-sprite.png?d=20111130 HTTP/1.1" 304 187 "" "Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0"

My answer:

I don’t think that that (.+.)? is supposed to be in there. In a working configuration I would have expected to see something like:

RewriteCond %{HTTP_REFERER} !^ [NC]

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.