Mahngiel Posted October 30, 2012 Share Posted October 30, 2012 I have an application that runs several sites on base configs, but allows those sites to change their imagery. As it stands right now, the image paths and .htaccess is as so: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule img/.+/(.*) img/$1 [L] www/ \ js/ \ img/ \\ site1/ \\ site2/ 1.png 2.png... <img src="img/{$Site->id()}/1.png" /> The .htaccess rule basically permits me to path all images to a user's account id, and when not found it serves from the base img directory. Nothing too special. I'd rather not have to deal with write permissions, so I've made an external repository that i'll save the images into. Basic structure is /repository/site/<site id>/<img>|<pdf>|<etc>. The code is versioned through github, so I don't think symlinks would work. To combat this, here is my weak attempt: # when the URI matches img/<id>/<img>, serve from repo path RewriteCond %{REQUEST_URI} img/.+/(.*) RewriteRule img/(.+)/(.*)$ /repository/sites/$1/$2 [L] # if that doesn't exist, server from web path RewriteCond /repository/sites/8/%{REQUEST_FILENAME} !-f RewriteRule img/.+/(.*) img/$1 [L] Produces logs like so: x.x.x.x- - [30/Oct/2012:14:59:28 --0400] [xx][rid#9cfe1d8/subreq] (1) [perdir /home/a/b/c/www/] internal redirect with /index.php/repository/sites/8/img/interface_splash.png [iNTERNAL REDIRECT] x.x.78.1 - - [30/Oct/2012:14:59:28 --0400] [xx][rid#9d3a7c8/initial] (1) [perdir /home/a/b/c/www/] internal redirect with /index.php/ [iNTERNAL REDIRECT] x.x.78.1 - - [30/Oct/2012:14:59:28 --0400] [xx][rid#9d8bdb8/initial/redir#1] (1) [perdir /home/a/b/c/www/] pass through /home/a/b/c/www/index.php x.x.78.1 - - [30/Oct/2012:14:59:28 --0400] [xx][rid#9d42a58/subreq] (1) [perdir /home/a/b/c/www/] internal redirect with /index.php/ [iNTERNAL REDIRECT] Any idea how I can dynamically server assets from outside the webroot? Quote Link to comment https://forums.phpfreaks.com/topic/270087-serve-images-from-outside-webroot/ Share on other sites More sharing options...
Mahngiel Posted October 30, 2012 Author Share Posted October 30, 2012 Solution (in httpd.conf): RewriteCond /repository/sites/$1/img/$2 -f RewriteRule img/(.+)/(.*) /repository/sites/$1/img/$2 [L] RewriteCond /repository/sites/$1/img/$2 !-f RewriteRule img/(.+)/(.*) /img/$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/270087-serve-images-from-outside-webroot/#findComment-1388837 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.