duansha3771 2014-11-05 06:27
浏览 51
已采纳

从外部Web根目录在Apache Server中运行Html文件

I have a folder which contain HTML, CSS, JS, image files across various folders. For security reasons I want to place it outside the web root.

I have come across a solution using file_get_contents function of PHP.

But then there is a problem with hyper-linking present in the page. For example, the link to the javascript file in the page:

<script src="lms/APIConstants.js" type="text/javascript"></script>

searches for the file in http://localhost/lms/APIConstants.js and returns an error of

Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/lms/APIConstants.js

I am aware of using .htaccess file for hiding some folders from the web root. I am looking for some other insightful solution.

  • 写回答

2条回答 默认 最新

  • dongmou3615 2014-11-12 09:57
    关注

    Finally solved this.. Might be helpful for others.

    Steps that were followed:

    • Use a separate file for reading from outside web root (say filereader.php).
    • Call this file with URL encoding the local file path. http://localhost.ca/lms/filereader.php/path/to/local/file.html
    • Parse the URL to get the path - /path/to/local/file.html
    • Apply PHP's readfile() function to read from the obtained path.

    Doing this, all the hyperlinks in file.html gets loaded from the following path.

    http://localhost.ca/lms/filereader.php/path/to/local/

    The mime-type for each file has to be defined. Also a proper http response code is to be thrown using PHP's http_response_code() when a file is not found.

    Note: You might need to enable AcceptPathInfo in the Apache configuration.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛