Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Blocking access to dir and sub dir folders from public view

durangod

Coder
Hi, so awhile back i got this from phpbb as it blocks access to certain folders. My question is do i have to create an htaccess in every folder OR list every folder in this code? I have a ton of folders and listing each one is madness. Originally i just started creating index.php files in each folder and leaving it blank but that too is alot of work and there has to be a better way. I dont want the public to be looking at my dir listings in my folders. I seem to remember something from php about this but its been a long time.

FYI i do already have this code in my root htaccess file

Code:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php

here is the code i got from phpbb

Code:
# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from
# module mod_authz_host to a new module called mod_access_compat (which may be
# disabled) and a new "Require" syntax has been introduced to mod_authz_host.
# We could just conditionally provide both versions, but unfortunately Apache
# does not explicitly tell us its version if the module mod_version is not
# available. In this case, we check for the availability of module
# mod_authz_core (which should be on 2.4 or higher only) as a best guess.
<IfModule mod_version.c>
    <IfVersion < 2.4>
        <Files "config.php">
            Order Allow,Deny
            Deny from All
        </Files>
        <Files "common.php">
            Order Allow,Deny
            Deny from All
        </Files>
    </IfVersion>
    <IfVersion >= 2.4>
        <Files "config.php">
            Require all denied
        </Files>
        <Files "common.php">
            Require all denied
        </Files>
    </IfVersion>
</IfModule>
<IfModule !mod_version.c>
    <IfModule !mod_authz_core.c>
        <Files "config.php">
            Order Allow,Deny
            Deny from All
        </Files>
        <Files "common.php">
            Order Allow,Deny
            Deny from All
        </Files>
    </IfModule>
    <IfModule mod_authz_core.c>
        <Files "config.php">
            Require all denied
        </Files>
        <Files "common.php">
            Require all denied
        </Files>
    </IfModule>
</IfModule>

Thanks Dave 🙂
 
Last edited:

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom