In code, my question is:开发者_运维百科
if(file_exists( c/ $requesturl )
serve( c/ $requesturl )
else
serve( index.php?blah )
In human form:
My script generates CSS. This is pretty intensive, so I built in caching.
People request: http://domain.com/css/1lfi4wg.css2
Which is rewritten:
RewriteRule ^([a-zA-Z0-9\-]*)\.css$ index.php?cssfilename=$1&generate
This works. After the above is visited, a cachefile is generated, which also works:
http:// domain.com/css /c/ 1lfi4wg.css2
Now I want to serve the generated file (/c/*) as the original request. I now do this in the php file itself, but I guess doing this with htaccess is quicker.
I now have this which does not work:
RewriteCond %{DOCUMENT_ROOT}/c/%{REQUEST_FILENAME} -f
RewriteRule ^(.*)\.css$ %{DOCUMENT_ROOT}/c/$1.css [L]
REQUEST_FILENAME already is an absolute file system path. Try the URI path in REQUEST_URI or the matched string of the RewriteRule
pattern instead:
RewriteCond %{DOCUMENT_ROOT}/c%{REQUEST_URI} -f
RewriteRule ^.*\.css$ %{DOCUMENT_ROOT}/c%{REQUEST_URI} [L]
# OR
RewriteCond %{DOCUMENT_ROOT}/c/$0 -f
RewriteRule ^.*\.css$ %{DOCUMENT_ROOT}/c/$0 [L]
精彩评论