views:

67

answers:

2

I have a web application that has one set of files used by 50+ clients and all the configuration for each site comes from a config.php file in their respective directories. This is accomplished with PHP parsing the URL. All this works fine, just having an issue with custom uploaded documents the client can do and are located in

/var/www/sites/user1/cache

There can be multiple subdirs. So when requesting http://user1.site.com/cache/subdir1/image.jpg it needs to be read from /var/www/sites/user1/cache/subdir1/image.jpg

The client is allowed to upload any file type, so I just need the rewrite to take any /cache requests, then grab the subdomain and point to proper directory.

Came up with this, but am still getting an invalid page

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

Any help is appreciated.

A: 

If I read the RewriteRule documentation correctly, the L flag on its own would generate an internal redirection, meaning that the substitution would be interpreted as a local file system path.

Try using the complete path:

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

or do an external redirection (using HTTP return status "302 MOVED TEMPORARILY"), to let the user's browser re-send the request with the new path:

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

Dave
A: 

The /var/www/ is where the files are on the filesystem. I was routing based on the document root so I didn't need to put that there. But I realized I was missing the leading forward slash on the /cache/. Though your answer wasn't really what I was looking for, it made me see what I was missing. Thanks.

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