.htaccess allow localhost problem

Leo's answer solved my issue. This is what I have set up so I can block direct access to images:

<IfModule mod_rewrite.c>
<Files ~ "\.(jpg|jpeg|png|gif|pdf|txt|bmp|mp4|mov|ogg|wmv|webm|flv|mpg|mp2|mpeg|mpe|mpv|m4p|m4v|mp3|wav|acc|oga|m4a)$">
   order deny,allow
   deny from all
   Require local
   allow from all
</Files>
</IfModule>

I didn't want to type out the ip, incase the local ip changed later


Require local

The local provider allows access to the server if any of the following conditions is true:

  • the client address matches 127.0.0.0/8
  • the client address is ::1
  • both the client and the server address of the connection are the same

This allows a convenient way to match connections that originate from the local host:

Require local


Use the order the other way around, ie:

order deny,allow
deny from all
allow from 127.0.0.1