RewriteEngine on
RewriteBase   /

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

###############################################################
# After configuring Apache for HTTPS, enable these two lines. #
# They will redirect http:// to https://                      #
###############################################################
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# If the install directory exists in the document root...
RewriteCond %{DOCUMENT_ROOT}/install/index.php -f
# ...and not in install directory...
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
# ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect.
RewriteRule !^install/ install/ [L,NC,R=302]

#Force reload of homepage bricks
RewriteRule ^parseBricks/?$ /client/bricks/parser.php [NC,L]

RewriteRule ^help(.*)$ /client/help$1 [NC,L]
RewriteRule ^images(.*)$ /client/images$1 [NC,L]
RewriteRule ^skins(.*)$ /client/skins$1 [NC,L]
RewriteRule ^js/vendor/(.*).js$ client/js/vendor/$1.js [NC,T=text/javascript,L]
RewriteRule ^js/vendor/(.*).css$ client/js/vendor/$1.css [NC,T=text/css,L]
RewriteRule ^js/(.*)$ client/js/$1 [NC,T=text/javascript,L]
RewriteRule ^device/.*/?$ device/index.php [NC,QSA,L]

RewriteRule ^api/imagepush/receive.php$ api/imagepush/receive.php [NC,QSA,L]
RewriteRule ^api/.*/?$ api/index.php [NC,QSA,L]

#Homepage is a special case, handle it here
RewriteRule ^/?$ client/index.php [NC,QSA,L]

#Don't redirect mod_shib URLs
RewriteRule ^Shibboleth\.sso - [L,NC]

#All others should be redirected to client
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*/?$ client/index.php [NC,QSA,L]