.htaccess Block direct access to subdirectories, but allow them to be called via JQuery/images/etc

谁说胖子不能爱 提交于 2019-12-25 03:23:54

问题


My main index.php calls a couple of scripts via JQuery from a subdirectory. I need to block direct access to any files in this directory, but allow them to be accessed by index.php. I have tried the simply:

deny from all

approach, but this blocks even Jquery from loading the script. There is also an /images subdirectory that needs to be blocked from direct access. deny all disallows the image from being called in any way. Does anyone know how to do this?


回答1:


just use the file-functions of php to get the content of the protected files, so only your php-file (e.g. index.php) is able to handle with the files of the protected dir.

useful functions are:

file_get_contents()

fread()

...

then you can include the js-code in your output-html or get the content out as image (then you should take a look at the header() function.



来源:https://stackoverflow.com/questions/11734924/htaccess-block-direct-access-to-subdirectories-but-allow-them-to-be-called-via

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!