Hi – I've been struggling with this for days. It seems simple but I just can't get it done.
I have a site developed in CakePHP. There's a script that responds to /css/profiles/g/whatever.css ("whatever" being whatever, it is actually a parameter that gets passed to the action), it echoes a generated CSS and saves it to /css/profiles/whatever.css.
I have a rule in Apache that takes requests to /css/profiles/whatever.css and, if it doesn't exist, rewrites the request to /css/profiles/g/whatever.css without redirecting, so the client never notices it was responded by a script and that the file didn't exist.
This is what I have in Apache:
# Profile CSS rules
RewriteCond %{REQUEST_URI} ^/css/profiles/
RewriteCond %{REQUEST_URI} !/css/profiles/g/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^css/profiles/(.*)$ /css/profiles/g/$1 [L]
# CakePHP's default rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Now I'm moving the site to a server with Nginx, and so far I've got this:
# Profile CSS rules
location ~ ^/css/profiles/(?!g/)(.*)$ {
if (!-f $request_filename) {
rewrite ^/css/profiles/(.*)$ /css/profiles/g/$1 last;
break;
}
}
# CakePHP's default rules
location / {
try_files $uri $uri/ /index.php?$uri&$args; }
The conditions seem to be working, because if I go to /css/profiles/whatever.css and print out PHP's $_SERVER variable it gives me
[QUERY_STRING] => /css/profiles/g/whatever.css&
Notice the &. It means it got to the try_files part and added the $uri to the query string, and it has the correct $uri.
But...
[REQUEST_URI] => /css/profiles/whatever.css
That's the glitch. It seems it's not really changing the $request_uri which is what CakePHP needs to control what controller attends what.
Any help will be appreciated.
Thanks.