1

I want to prevent hotlinking to all subfolders in /var/www/store but at the same time allow linking to its index page. I tried doing this:

<Directory "/var/www/store">
  DirectoryIndex index.html
</Directory>
<Directory "/var/www/store/*">
  SetEnvIfNoCase Referer ^http://example.com/ accept
  Require env accept
</Directory>

But the index.html is forbidden when I tried accessing from a link outside. Next I tried appending a trailing slash.

<Directory "/var/www/store/*/">

It doesn't work too. Is this a bug in Apache? Ain't the <Directory> directive supposed to match directories only?

Question Overflow
  • 2,023
  • 7
  • 28
  • 44

1 Answers1

1

In my experience, <Directories> match anything in a directory or subdirectory.

I've not done this before, but this would seem correct behavior to me. Why not try fold the 2 Directory entries into 1 and add

SetEnvIfNoCase Request_URI ".html" accept

Abhijeet Kasurde
  • 985
  • 9
  • 20
davidgo
  • 5,964
  • 2
  • 21
  • 38
  • Can you clarify the first point? Sorry, I don't quite get it. For the second point, yes, that's a good suggestion. I would try that. – Question Overflow Aug 03 '14 at 04:16
  • I don't think you need Directory "/var/www/store/*" and "Directory "/var/www/store/" - you can simply have "Directory "/var/www/store/" and add the SetEnv and require env stuff in that virtualhost along with the DirectoryIndex parameter if that is needed. – davidgo Aug 03 '14 at 04:23
  • To clarify again, I am asking why `index.html` is matched by ``, resulting in a Forbidden error, since it is supposed to be matching directories and subdirectories. – Question Overflow Aug 03 '14 at 04:32
  • matches "the named directory, sub-directories of that directory, and the files within the respective directories." (See http://httpd.apache.org/docs/2.2/mod/core.html#directory) - ie Files are also matched. – davidgo Aug 03 '14 at 04:39