RewriteEngine On

# If your hosting requires a RewriteBase, you have to add it here, too.
# Set it the the base of your frontend plus '/data/dyn/public/sally/static-cache/'.
# RewriteBase /.../data/dyn/public/sally/static-cache/

AddType text/css less

SetEnvIfNoCase ^Accept-Encoding$ ".*" HTTP_ENCODING_CACHEDIR=plain/

<IfModule mod_headers.c>
	Header set Cache-Control "max-age=29030401"
	SetEnvIfNoCase ^Accept-Encoding$ "deflate"          HTTP_ENCODING_CACHEDIR=deflate/
	SetEnvIfNoCase ^Accept-Encoding$ "gzip"             HTTP_ENCODING_CACHEDIR=gzip/
</IfModule>

# generate cache file if missing
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              !.*static-cache/(public|protected)/(gzip|plain|deflate).*
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              (.*static-cache/)(.*)
RewriteCond %1public/%{ENV:HTTP_ENCODING_CACHEDIR}%2     !-d
RewriteCond %1public/%{ENV:HTTP_ENCODING_CACHEDIR}%2     !-f
RewriteCond %1public/%{ENV:HTTP_ENCODING_CACHEDIR}%2     !-l
RewriteCond %1protected/%{ENV:HTTP_ENCODING_CACHEDIR}%2  !-d
RewriteCond %1protected/%{ENV:HTTP_ENCODING_CACHEDIR}%2  !-f
RewriteCond %1protected/%{ENV:HTTP_ENCODING_CACHEDIR}%2  !-l
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              !cache\.php
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              !protect\.php
RewriteRule (.*)                                         ../../../../../index.php?slycontroller=asset&sly_asset=$1 [QSA,L]

# handle permissions
# "data/dyn/public/sally/static-cache/assets/favicon.ico"
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              !.*static-cache/protected/(gzip|plain|deflate).*
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              (.*static-cache/)(.*)
RewriteCond %1protected/%{ENV:HTTP_ENCODING_CACHEDIR}%2  -f
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              !cache\.php
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}              !protect\.php
RewriteRule ^(.*)$                                       protect.php?file=$1 [L]

# stream the file directly through Apache
# "data/dyn/public/sally/static-cache/assets/favicon.ico"
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}    !.*static-cache/public/(gzip|plain|deflate).*
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}    !cache\.php
RewriteCond %{REQUEST_FILENAME}%{PATH_INFO}    !protect\.php
RewriteRule ^(.*)$                             public/%{ENV:HTTP_ENCODING_CACHEDIR}$1 [L]
