Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling Indexes (folder views) using htaccess with Apache 2.4 mod_authz_host based on IP

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.

like image 487
Michael Fever Avatar asked Dec 29 '25 18:12

Michael Fever


1 Answers

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.

like image 79
Michael Fever Avatar answered Dec 31 '25 18:12

Michael Fever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!