I need to keep all my files and folders of my website in public_html folder. There are some folders for javascript codes like 'Javascript' and css codes like 'CSS', 'Images' for images, etc. It is easy for any visitor to type just the folder address like 'http://www.website.com/Javascript' and he will have permission to see all my javascript codes. I want to restrict these folders from visitors and use only for my scripts which are uploaded in public_html folder. How can this be done? Please give solution for my scripts in public_html also, which will need to access those folders.
1 Answer
For your security purpose you can set access permission for the public access for particular files, folder etc with the apache .htaccess file.
In your case create .htaccess file in the folder name public_html and put the bellow htaccess configuration:
Completely restricted from web server.
Deny from all
Restrict folder, sever can access files.
Options -Indexes
This works for me.
-
1
-
Actually it worked when I put the .htaccess file in the folder which I wanted to protect and put the code 'Deny from all' in it. I'm not sure, but I think this will work. Apr 17, 2017 at 5:09
-
Sure, but now those files can not be loaded from web pages that reference them. Apr 17, 2017 at 5:11
-
Yeah @john, this will protect particular folder only. if you want to configure for entire site you have to configure in the root folder.– GeeeApr 17, 2017 at 5:13
-
Alex, do you know any other way to protect my folders? If yes, please share. Apr 17, 2017 at 7:06
Options -Indexes
. But note this will not disable the ability to download the files if you know the name, and will not prevent people from being able to see the source code of your site.