
<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase X-REWRITEBASE-X

# tell PHP (via $_SERVER) that the server supports .htaccess
RewriteRule .* - [env=HTACCESS_SUPPORT:1]

# --- Short URL Rewrites
# rule for keyword search (s=Search+String)
RewriteRule ^[sS]=(.+)$ index.php?P=AdvancedSearch&Q=Y&FK=$1 [L,R]


# --- CWIS PLUGIN SUPPORT

# --- BackwardCompatibility
# mapping old page URLs to new application framework
RewriteRule ^SPT--(.+)\.php$ index.php?P=$1 [L,QSA]
# mapping old UI paths
RewriteRule ^SPTUI--CWIS/(.+)$ interface/default/$1 [L]
RewriteRule ^SPTUI--Standards/(.+)$ interface/LowVision/$1 [L]
RewriteRule ^SPTUI--([a-zA-Z0-9]+)/(.+)$ local/interface/$1/$2 [L]

# --- OpenIdServer
RewriteRule ^oid/userXrds$ plugins/OpenIdServer/server.php/userXrds [L,QSA]
RewriteRule ^oid/trust$ plugins/OpenIdServer/server.php/trust [L,QSA]
RewriteRule ^oid/login$ plugins/OpenIdServer/server.php/login [L,QSA]
RewriteRule ^oid/(.+)$ plugins/OpenIdServer/server.php/idpage?user=$1 [L,QSA]
RewriteRule ^oid/?$ plugins/OpenIdServer/server.php [L]

# ----- APPLICATION FRAMEWORK SUPPORT

# -- URL fingerprinting support
RewriteRule .* - [env=URL_FINGERPRINTING_SUPPORT:1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !=URLF=1
RewriteRule ^(.+)\.[0-9A-F]{6}\.([a-z]+)$ $1.$2?URLF=1 [L]

# -- SCSS support
RewriteRule .* - [env=SCSS_REWRITE_SUPPORT:1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !=SCSS=1
RewriteRule ^(.+\.css)$ local/data/caches/SCSS/$1?SCSS=1 [L]

# -- JavaScript auto-minification support
RewriteRule .* - [env=JSMIN_REWRITE_SUPPORT:1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !=JSMIN=1
RewriteRule ^(.+\.js)$ local/data/caches/JSMin/$1?JSMIN=1 [L]

# -- ViewImage cache
RewriteRule ^viewimage/([0-9]+_[0-9]+_[0-9]+_[fpt](\.[a-z]+)?)$ local/data/caches/ImageLinks/$1

# -- ADDITIONAL-REWRITES-GO-HERE
# -- (any additional rewrite directives should go here, 
# --        because rewrites for clean URL support need to be last)

# -- Clean URL support
# tell PHP (via $_SERVER) that clean URL support is okay
RewriteRule .* - [env=CLEANURL_SUPPORT:1]
# catch anything not an existing file or directory (for clean URLs and 404s)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

</IfModule>

# -- Cache Policy (static assets and fingerprinted files)
<FilesMatch "\.(css|js|png|jpe?g|gif|ico|swf|flv|mp4|pdf|docx?|pptx?|zip|woff)$">
  Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# -- Enable compression if available
<IfModule mod_version.c>
<IfVersion >= 2.4>
<IfModule mod_mime.c>
<IfModule mod_deflate.c>
AddType application/x-font-woff woff
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-font-woff
</IfModule>
</IfModule>
</IfVersion>
</IfModule>

