-2

I have the following structure for my filesystem

public_html
 css/
 doc/
 img/
 js/
 lib/
 *.php

private_html
 miscellaneous/

The document root in for my website is set in /etc/apache2/site-available as

DocumentRoot /var/www/public_html

Currently this allows users to direct access to files from the url like mysite.com/css/custom.css and mysite.com/lib/...

What is the best way to prevent direct access to these files? Should I just restructure the filesystem like this:

public_html
 *.php

private_html
 css/
 doc/
 img/
 js/
 lib/
 miscellaneous/

And update the paths of the included scripts in the php files?

2
  • 2
    I don't underhand why you want to do this, or what it is that you're trying to achieve. A browser will need direct access to the files if it is to load them as part of a page,unless you're going to dynamically include content with php which doesn't make much sense.
    – squillman
    Mar 18, 2012 at 11:48
  • And even if you include your static .js and .css etc. in the HTML, it's still downloaded by the user and he can extract it from the page source.
    – Sven
    Mar 18, 2012 at 12:32

1 Answer 1

1

You can't, because a "direct" request is exactly the same as a request made in pursuit of a static asset. Whatever you're trying to achieve, it's almost certainly wrong and misguided, but at the very least you'll want to describe what you're trying to achieve, not ask how to implement whatever solution you've already come up with, because it's just plain wrong.

2
  • How do I redirect anyone who goes to mysite.com/js/* back to mysite.com/? Would that involve mod_rewrite?
    – user784637
    Mar 18, 2012 at 11:55
  • 2
    Put questions in questions, not comments.
    – womble
    Mar 18, 2012 at 11:56

Not the answer you're looking for? Browse other questions tagged .