I've got a web application which has a bouquet of files utilized by 50+ clients and all sorts of the configuration for every site develops from a config.php file within their particular sites. This is achieved with PHP parsing the URL. All of this works fine, just getting an problem with custom submitted documents the customer can perform and therefore are situated in


There might be multiple subdirs. Then when asking for http://user1.site.com/cache/subdir1/image.jpg it must be read from /var/www/sites/user1/cache/subdir1/image.digital

The customer is permitted to upload any file type, and so i only need the rewrite to consider any /cache demands, grab the subdomain and indicate proper directory.

Emerged with this particular, but am still getting an invalid page

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.site\.com$
RewriteRule ^cache/(.*)$ /sites/%1/cache/$1 [L]

Any assistance is appreciated.

Basically read the RewriteRule documentation properly, the L flag by itself would generate an interior redirection, and therefore the substitution could be construed like a local file system path.

Use the entire path:

RewriteRule ^cache/(.*)$ /var/www/sites/%1/cache/$1 [L]

or do an exterior redirection (using HTTP return status "302 MOVED TEMPORARILY"), to allow anyone's browser re-send the request using the new path:

RewriteRule ^cache/(.*)$ /sites/%1/cache/$1 [L,R]

The /var/www/ is how the files take presctiption the filesystem. I had been routing in line with the document root and so i did not have to put there. However I recognized I had been missing the key forward slash around the /cache/. Though the way to go wasn't really things i was searching for, it helped me see things i didn't have. Thanks.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.site\.com$
RewriteRule ^/cache/(.*)$ /sites/%1/cache/$1 [L]