3

How can I enable Indexes only for specific IP addresses?

Generally, I want directory listing to be disabled but only be enabled for a specific IP

2
  • 3
    found this old unanswered question first, then stumbled over the answer in serverfault.com/a/531674/332079 Commented Nov 25, 2016 at 10:12
  • Oh noez, 6 years too late :-/ But thx anyway, very interesting what's possible 😁
    – mark
    Commented Nov 25, 2016 at 14:48

3 Answers 3

3
<Directory /path/to/your/dir>
  Options indexes
  order deny,allow
  deny from all
  allow from 192.168.1.101
</Directory>

If that doesn't do what you want (as nothing in the directory is not accessible period to anyone but the specified IP), you can do something that accomplishes what appears to be enabling indexes for a specific IP with mod_rewrite:

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.101
RewriteRule ^/(index\.html)?$ /page_to_kick_people_looking_for_indexes_to.html [L]
0

Using the mod_authz_host in Apache 2 (or mod_access in Apache 1), you can limit access control to a Directory by IP address (or IP address range).

For example:

<Directory "/path/to/directory/">
Order allow,deny
Allow from XXX.XXX.XXX.XXX
Options Indexes
</Directory>

For more information see the Apache page for mod_authz_host.

0

If you create 2 <Directory /> entries you can show indexes for a specific IP or range and disable indexes for all others, like so:

<Directory "/path/to/directory">
    Order deny,allow
    Allow from all
    Options -Indexes
</Directory>

<Directory "/path/to/directory">
    Order allow,deny
    Allow from 192.168.1.101
    Options +Indexes
</Directory>

EDIT:

I now see that this also disables access to single files so it's still only accessible from one IP/range

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .