What Is The Best Way To Deny Access To Directories?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

What Is The Best Way To Deny Access To Directories?

Postby DeveloperDan » 23. January 2018 00:07

Hello everyone! I am new to the forums and looking to solve a problem. My apologies in advance if I am not asking my question in the proper location. I will do my best to explain my problem in such a way that supplying an answer should be simple. At least I hope. :) :)

____________________________
Example Directory Structure:
____________________________
root/
/js/
/css/
/images/
/new_images/
/old_images/
/misc/
/misc_one/
/misc_two/
index.php
about.php
contact.php
.htaccess
robots.txt
____________________________

The above is my example of a simple file structure 3 levels deep. (E.g: root/images/new_images). My actual website is a WordPress website and file structure.

What do I want to achieve or prevent? I want to stop anyone from being able to directly access a directory and view its contents by simply visiting the directory path. I know I could drop an index.php/HTML file in each directory but there are just too many, some directories are created dynamically and it's just not practical. When I visit mywebsite.com/images/ or www.mywebsite.com/misc/misc_two or any other directory with no index file in it I want to either redirect the user to a specific page or show them nothing. So long as I have control of what they see or don't see.

The Short Version Of My Question:
-----------------------------------------
How do I keep people from viewing the contents of any and all the directories on my website using the .htaccess file? Is there a directive to redirect visitors to another page once they've manually entered into a directory with no index file? I do not want anyone to be able to look into a directory. Keep ni mind I am using this on a wordpress website.

As always, thank you all for reading and I hope to hear from you soon!

Regards
DeveloperDan
DeveloperDan
 
Posts: 2
Joined: 22. January 2018 23:29
XAMPP version: 3.2.2
Operating System: Windows 10

Re: What Is The Best Way To Deny Access To Directories?

Postby Altrea » 23. January 2018 00:52

Hi DeveloperDan,

Short Answer: Wordpress already comes with a predefined .htaccess file which uses a Front Controller Pattern to generate SEO-URLs.
https://codex.wordpress.org/htaccess

best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9051
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: What Is The Best Way To Deny Access To Directories?

Postby DeveloperDan » 23. January 2018 22:40

Thank you very much for your answer. Kind regards!
DeveloperDan
 
Posts: 2
Joined: 22. January 2018 23:29
XAMPP version: 3.2.2
Operating System: Windows 10

Re: What Is The Best Way To Deny Access To Directories?

Postby Nobbie » 24. January 2018 11:46

Just in case you are interested in a solution without wordpress:

The easiest solution is identical to the default installation, deny access to the root folder (Require none) and then apply permission to any file/folder that may be read (Require All Granted).There is also the option if installing a sophisticated URL rewrite mechanism, or apply Rights in conjunction with file pattern (<FilesMatch...) or Locations (Location matches against the URL, where File matches against the physical path). There are lots of different options to do so, it requires a little analysis in order to determine which way suites best.

WIth the help of ALIAS you also have the option to put files and folders to pathes somewhere else. There is also "Option -Indexes", which deny directory listings. And and and .... there are plenty of solutions. But of course, it requires some knowledge in Apache configuration, what you cannot learn in a few hours. Apache configuration is a demanding task and requires a lot of effort.
Nobbie
 
Posts: 9991
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 42 guests