2

for security reason I want to store uploaded images outside of documentsroots.

here's (an example of) my .htaccess

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

I am trying to display my images file like this php line below without success

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

Can someone give me tips on how to proceed?

Thanks

Syscall
  • 19,327
  • 10
  • 37
  • 52
lome
  • 21
  • 1
  • Static files must be inside the document root. If you want the images outside, you need to create a PHP file that takes the request, reads the file from outside the web root and outputs it. A PHP file as a proxy. – M. Eriksson Feb 05 '18 at 20:36

1 Answers1

2

If you can modify the virtualhost itself (or an included config file), then you can use the Alias directive (it can't be used within an .htaccess file, unfortunately):

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.

Try

Alias /images /path/outside/documentsroots/images
Community
  • 1
  • 1
iainn
  • 16,826
  • 9
  • 33
  • 40
  • Hello iainn, no I can only use .htaccess – lome Feb 06 '18 at 10:27
  • Unfortunately your options are a bit limited here - for security reasons, it's deliberately not easy to access files outside of the document root. You need access to more "system-level" configuration, either the vhost or to create a symlink. If your PHP process has read access to the file, then you might be able to create a script to proxy the files - this link might be useful: https://stackoverflow.com/questions/13357994/access-a-file-which-is-located-before-outside-the-server-root-directory – iainn Feb 06 '18 at 10:47