I have a website like http://example.com but the problem with it is that people are able to get access to my JavaScript by pointing a browser to http://example.com/js/.

I have little knowledge of using .htaccess files.

2 Answers 2


To prevent directory listings when a directory is requested (that doesn't contain a DirectoryIndex) you can add the following to your .htaccess file in the root of your site:

Options -Indexes

This will result in a 403 Forbidden being served for http://example.com/js/, rather than the server generating a directory listing.

As Jobin Jose suggests, you can add a (blank) index.html to these folders (the DirectoryIndex document). However, you will need to do this for every folder and this will serve a blank page (or whatever you decide to put in index.html), returning a successful HTTP status (200 - OK).

However, you can't reliably block users from viewing your JavaScript files that you are referencing in your client-side pages.


Simply add an index.html (with no content) in your js folder.

that will prevent listing of your js files in the browsers.

no need of htaccess usage here. This will prevent your js file listing only access with proper js file names.

Hope its helps..

  • i have tried that but it doesn't work
    – csandreas1
    Commented Jan 2, 2017 at 21:56
  • Which server are you using ? it should works make sure file extension is correct
    – Jobin
    Commented Jan 3, 2017 at 3:23
  • i am using heroku
    – csandreas1
    Commented Jan 3, 2017 at 7:48

Your Answer

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

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