Block direct access to subfolders with .htaccess or other methods

2.1k Views Asked by At

Sorry for my bad english :)

I've a question.

How can i block with an error page, or redirect an user that is trying to access subfolders, in my website? I don't need password protected folders but just a displayed error for all subfolders.

Example:

www.mysite.com/folder - this folder content should not be visible to users

1

There are 1 best solutions below

0
On

This is a simple solution without editing the .htaccess file.

Create a new index.html or index.php file in your folder and write these line on the body.

In PHP:

    <?php    
      header("Location:../index.php");
    ?>

In HTML:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="1;url=http://www.yourDomainName.com">
    <script language="javascript">
        window.location.href = "http://youDomainName.com"
    </script>
    <title>Page Redirection</title>
</head>
<body>
    If you are not redirected automatically, follow the <a href='http://www.yourDomainName.lk'>link to Your domain name home page</a>
</body>
</html>

From this way you can block

www.yourDomain.com/img

folder

www.yourDomain.com/css

folder and other folders you wish to deny access easily. I don't know still can hackers bypass this files but this is the simple solution. Try this and see the answers for yourself.