Forum Moderators: phranque

Message Too Old, No Replies

different 'Options Indexes' rules for same directory?

         

jabez

2:19 pm on Jan 16, 2007 (gmt 0)

10+ Year Member



Is it possible to write an apache httpd.conf rule that will allow directory indexing options based on the IP address of the user requesting the page?

I would like to turn directory indexing on for myself from localhost (10.0.0.1) with something like:


<Directory /srv/www/my-websites>
Options None
Options Indexes
Order deny,allow
Deny from all
Allow from 10.0.0.1
# normally with this not be commented out, 10.0.0.3 would have
# the same access to directories as main server 10.0.0.1
Allow from 10.0.0.3
</Directory>

and not allow anyone else on the internet to get a directory listing for the same directory. How do I allow any user on the internet access to the above directory, but without them getting a directory listing like I have from localhost?

Is this possible and if so, how do I go about implementing it? Do I need two separate directory containers for each Options Indexes rule?

TIA

jdMorgan

3:39 am on Jan 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could enable Options Indexes as shown, and then use mod_rewrite in httpd.conf to block index requests from any except your own IP address:

RewriteCond %{REMOTE_ADDR} !^10\.0\.0\.1$
RewriteRule ^/([^/]+/)*$ - [F]

As shown, this will block access to any URL-path ending in "/" -- any directory index, that is. Adjust the pattern to suit your needs.

Jim