出于安全原因,我想将上传的图像存储在文档根目录之外。
这是我的 .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/