[eluser]picardo[/eluser]
(SOLVED. Scroll down to see the solution.)
I am trying to build a multi-app site, where the assets for all apps will be stored in a single folder called "assets." Inside this single folder, each app would have its own asset folder. So, if this is my root directory...
user_guide
apps_folder (this is where all my application folders live)
system
assets
...the assets folder will be organized thus:
assets
myapp1
js
img
css
media
Here is my challenge. I am trying to write an apache directive that would rewrite all requests for files ending in css, js, png and gif to the respective asset directory for that app. But the user cannot know the exact location of those assets in the server. To give you an example:
Here is the request: myapp1.localhost.dev/js/jquery.js
The file is located in: assets/myapp1/js
The directive I am hoping to write will check for
a) the domain address
b) file extension
...and based on those variables, will rewrite the url, thereby hiding thee real location of the asset, and make it possible to reference assets as if they were all located at the root of the website. Has anyone ever done something like this?
I have tried this"
RewriteCond %{HTTP_HOST} myapp1\.localhost\.dev$
RewriteRule ^/js/(.*)\.js$ assets/myapp1/js/$1
But it didn't work.
thanks,
EDIT: I did manage to make the lines above to work. Turns out there was a syntax error. I am posting the final result here to guide others.
########
###Each request to an asset is redirected to the application's own folder inside "assets."
###Reproduce and modify the two lines below for every domain.
######## myapp1
RewriteCond %{HTTP_HOST} myapp1\.localhost\.dev$
RewriteRule ^(js|css|img|media)/(.*)\.(js|css|gif|swf|png|jpg|ico)$ /assets/myapp1/$1/$2.$3
########
########
###Redirect all requests except these through the bootstrap file.
########
RewriteCond $1 !^(assets|.*\.js|.*\.css|.*\.gif|.*\.swf|.*\.png|.*\.jpg|.*\.ico|user_guide|index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]