3

Need to enable Indexes in apache 2.4 throughh htaccess based on IP.

For example, IP 192.168.x.x

I tried putting the directive in the apache2.conf file like:

    <Directory /var/vhosts/lubrigard.com>
            Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
    </Directory>

then

    <Directory /var/vhosts/lubrigard.com>
            Options +Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require ip 192.168
    </Directory>

However for any other IP it was denying any access to the folder.

So I disabled Indexes site wide and want to put an .htaccess file to enable Indexes for the internal IP addresses. Unless someone can tell me how to do it within the apache2.conf file.

Michael Fever
  • 845
  • 2
  • 8
  • 26

2 Answers2

2

This works, it displays a "Forbidden, You don't have permission to access /folder/ on this server." instead of "Directory listings denied." I am able to access files within that folder still.

 <If "%{REMOTE_ADDR} == '192.169.0.95'">
 Options +Indexes +FollowSymLinks +MultiViews
 Require all granted
 </If>
 <Else>
 Options -Indexes +FollowSymLinks +MultiViews
 Require all granted
 </Else>

I have also tried:

 <If "%{REMOTE_ADDR} == '192.169.0.95'">
 Options +Indexes
 </If>
 <Else>
 Options -Indexes
 </Else>

Both have worked. My only issue is that I didn't want to specify the full IP. I would have rather it use the first 3 bytes of the IP: 192.168.0.xxx

For some reason, if Indexes is not enabled then the user has no access to the content on in this folder. I am just looking to disable the directory listings, not block access to files in that folder.

Michael Fever
  • 845
  • 2
  • 8
  • 26
1

Thanks! This is what I was looking for and it works.

As for your question...

Both have worked. My only issue is that I didn't want to specify the full IP. I would have rather it use the first 3 bytes of the IP: 192.168.0.xxx

Try this: <If "-R '192.168.0.0/24'">

Reference: http://httpd.apache.org/docs/trunk/expr.html

David Hatch
  • 2,406
  • 1
  • 17
  • 11