1

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.

7
  • you can minify & uglify the js code
    – brk
    Apr 17, 2017 at 4:39
  • "How can this be done?" It can't be. JS and CSS files are rendered client side. You can not prevent people from being able to access them and still expect your site to work. Apr 17, 2017 at 4:47
  • I just do not want them to enter my folder. It will not be a problem if they can see javascript files of the page they are browsing. But I want to limit access of viewers to the entire folder where I keep all my codes. @Alex
    – John Wink
    Apr 17, 2017 at 7:10
  • If you just want to disable directory listings, then you want 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. Apr 17, 2017 at 13:31
  • 1
    "I just do not want them to enter my folder." - add empty index.php to each folder.
    – DmitryoN
    Aug 29, 2019 at 3:23

1 Answer 1

1

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.

6
  • 1
    Erm... this will shut down your whole site. Apr 17, 2017 at 5:08
  • 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.
    – John Wink
    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.
    – Geee
    Apr 17, 2017 at 5:13
  • Alex, do you know any other way to protect my folders? If yes, please share.
    – John Wink
    Apr 17, 2017 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.