What Is The Best Way To Deny Access To Directories?
Posted: 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
____________________________
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