php - htaccess RewriteRule 读取文档根目录之外的图像

标签 php image apache .htaccess mod-rewrite

出于安全原因,我想将上传的图像存储在文档根目录之外。

这是我的 .htaccess(示例)

RewriteEngine on
RewriteRule ^images/(.*) /path/outside/documentsroots/images/$1

我正在尝试像下面的 php 行一样显示我的图像文件,但没有成功

echo <img SRC="images/myPic.png">

有人可以给我一些如何继续的提示吗?

谢谢

最佳答案

如果您可以修改虚拟主机本身(或包含的配置文件),那么您可以使用 the Alias directive (不幸的是,它不能在 .htaccess 文件中使用):

There are frequently circumstances where it is necessary to allow web access to parts of the filesystem that are not strictly underneath the DocumentRoot. Apache offers several different ways to accomplish this. On Unix systems, symbolic links can bring other parts of the filesystem under the DocumentRoot. For security reasons, Apache will follow symbolic links only if the Options setting for the relevant directory includes FollowSymLinks or SymLinksIfOwnerMatch.

Alternatively, the Alias directive will map any part of the filesystem into the web space.

尝试

Alias /images /path/outside/documentsroots/images

关于php - htaccess RewriteRule 读取文档根目录之外的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48630951/

相关文章:

javascript - 根据 Laravel 中的状态显示人员目录

javascript - 如何在 if 或 else 语句中添加图片而不是文本

html - 无论图像比例如何,都生成方形缩略图

ruby-on-rails - 乘客加载错误 - 无法加载此类文件 -- phusion_passenger (LoadError)

php - 如何将我的 WAMP 放到网上供其他人访问?

apache - 404 的标准 Apache 错误文档的位置是什么?

php - POST 数据正在从 HTML 实体中剥离

php - 在加载 ajax 的页面内无限滚动

php - 如何使用Jquery ajax设置$_SESSION?

image - 如何检测鼠标何时不再位于控件中?