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 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?

share|improve this question

closed as not a real question by womble, Tom O'Connor, Ward, Lucas Kauffman, Michael Hampton Aug 3 '12 at 5:02

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

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 '12 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. –  SvW Mar 18 '12 at 12:32

1 Answer 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.

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

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