Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've noticed on some sites, when I go to eg. www.example.com/js where there javascript is stored, it is forbidden.

On my website currently, if users browse to www.mysite.com/js they will see all of my javascript files nicely arranged into folders. How can I prevent them from browsing this directory and still keep my javascript working correctly?

PS. I know the user downloads the javascript when they use my site and there is no way to prevent someone from reading the source but I would like to prevent what I am describing, as I see other sites have achieved this.

Thanks.

share|improve this question
1  
This is a webserver setting. The exact answer depends on the webserver make/version used. Please mention which one you're using. –  BalusC Sep 17 '10 at 19:47
    
It is Linux hosting with cPanel Control. is that what you mean? –  David Willis Sep 17 '10 at 19:51
    
Not exactly, but in ~90% of such hosts they're using Apache HTTPD. –  BalusC Sep 17 '10 at 19:55
add comment

migrated from stackoverflow.com Sep 21 '10 at 0:57

This question came from our site for professional and enthusiast programmers.

5 Answers

It is Linux hosting with cPanel Control. is that what you mean?

It's likely using Apache HTTPD server. Drop a .htaccess file in the JS folder with the following content:

Options -Indexes 

This will disable directory indexing.

share|improve this answer
add comment

Ok, all of those people's answers are totally good and valid.

However, there's a much, much, much simpler way of acheiving this:

  1. Create a blank text file inside the JS folder called index.html
  2. ???
  3. Profit!
share|improve this answer
add comment

This is really a question for ServerFault, but you should be able to forbid directory indexes in the /js directory. You could also block access from browsers that don't present a referrer string in your site, though that might break some browsers.

share|improve this answer
add comment

use the .htaccess sent below, =] ... and you can compress your js files to improve the performance and to ensure the "privacy" of your scripts too:

http://javascriptcompressor.com/

http://developer.yahoo.com/yui/compressor/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.