Best unofficial Apache Server developers community |
|
ex. there are css folder storing css files and page folder storing html,php. anyone trying to access css folder from http request will be denied. but any pages in page folder will able to use css files in folder css In other word,only files in page folder can use files in css folder can we do this?
posted via ServerFault
|
|
 
|
normally all the requests to css files are coming with a referer set to the page that uses the css. so you can forbid access to css files if the request comes with a referer different than http://yoursite.com/page/ full example: apache vhost config:
the docroot setup:
issuing a direct request to /css/x.css, rewrite.log snip:
issuing a request to /page/x.html, page content is:
request to http://t1/page/x.html:
so it works as expected. however, no one stops anyone to issue a fake referer with the request. the technique I described is used to kill leeches. |
|
 
|
I do not think this is possible the way you describe it, because on the server side you cannot distinguish if a resource has been requested individually or as part of a page. There are simply separate HTTP requests the user's browser makes, first requesting the page itself, then the required resources such as images, stylesheets and the likes. What would be possible instead is inlining the stylesheets on the server side using Server Side Includes or any other dynamic server-side technology. You mentioned using PHP, so you could simply put your pages together on the server side and send them as a single response while keeping the CSS folder restricted for direct access. This will not keep people from accessing your stylesheets, though. They are simply part of the page then instead of separate files. |