RewriteMap lc int:tolower
RewriteEngine On

RewriteRule . - [E=WARPDEV:]
RewriteRule . - [E=WARPTARGET:]
RewriteRule . - [E=cors:1]
RewriteRule . - [E=isInternal:0]

RewriteCond %{QUERY_STRING} ^profileType=([0-9]*)&(.*)$
RewriteRule . - [E=X_ADA_PROFILETYPE:%1]

RewriteCond %{QUERY_STRING} ^rebuildCache=([0-9_]*)&(.*)$
RewriteRule . - [E=X_ADA_ISREBUILD:1]

RewriteCond %{QUERY_STRING} preview=(.*)(&?)$
RewriteRule . - [E=X_ADA_ISPREVIEW:true]

RewriteCond %{QUERY_STRING} !preview=(.*)(&?)$
RewriteRule . - [E=X_ADA_ISPREVIEW:false]

RewriteCond %{QUERY_STRING} userDomain=(.*)(&?)$
RewriteRule . - [E=X_ADA_HTTP_HOST:%1]

RewriteCond %{QUERY_STRING} !userDomain=(.*)(&?)$
RewriteRule . - [E=X_ADA_HTTP_HOST:%{HTTP_HOST}]

RewriteCond %{HTTP:X_ADA_INTERNAL} !^$
RewriteRule . - [E=isInternal:1]

RewriteMap sitesmap "dbm:${ADA_SITE_ROOT}/config/apache/dist/sta-sites-db.map.db"
RewriteRule . - [E=X_ADA_PRODTYPE:${sitesmap:%{ENV:X_ADA_HTTP_HOST}|null}]

RewriteCond %{HTTP:X_ADA_DEVICETYPE} !^$
RewriteRule . - [E=X_ADA_DEVICETYPE:%{HTTP:X_ADA_DEVICETYPE}]

RewriteCond %{REQUEST_URI} _json.shtml
RewriteRule . - [E=WARPTARGET:_json]

RewriteCond %{REQUEST_URI} ^/ada-serviceWorker-staging.js$ [OR]
RewriteCond %{REQUEST_URI} ^/ada-serviceWorker.js$
RewriteRule ^/(.*)$ https://assets.%{HTTP_HOST}/$1 [E=cors:0,NC,P]

RewriteCond %{HTTP_HOST} ^${X_ADA_HTTP_HOST} [NC]
RewriteCond %{REQUEST_URI} ^/optin/([A-Za-z0-9]+)\/?([A-Za-z0-9]*)\/?$
RewriteRule ^/optin/([A-Za-z0-9]+)\/?([A-Za-z0-9]*)\/?$ http://actions.${X_ADA_HTTP_HOST}/optin/optin.php?id=$1&user=$2 [E=cors:0,NC,P]

<IfModule mod_headers.c>
    Include ${ADA_SITE_ROOT}/config/apache/dist/static-fe-headers.conf
</IfModule>

RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9]+)?$
RewriteCond %{QUERY_STRING} token=(.*)(&?)
RewriteCond %{REQUEST_URI} !^/personalizations/(.*)?$
RewriteCond %{REQUEST_URI} !^/content_includes/
RewriteCond %{REQUEST_URI} !^/common_includes/
RewriteCond %{REQUEST_URI} !^/user_includes/
RewriteCond ${ADA_SITE_ROOT}/skeleton-pages/index%{ENV:WARPDEV}.shtml -f
RewriteRule ^/([A-Za-z0-9]+)?$ ${ADA_SITE_ROOT}/skeleton-pages/index%{ENV:WARPDEV}.shtml [L,E=X_ADA_PRODUCT:$1,E=X_ADA_PROFILETOKEN:%1,E=X_ADA_PROFILE:NOCONTENT,E=STATUS:product,E=X_ADA_PROFILETYPE:2]

RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9]+)/([A-Za-z0-9]+)\/?$
RewriteCond %{REQUEST_URI} !^/personalizations/(.*)?$
RewriteCond %{REQUEST_URI} !^/userSettings/
RewriteCond %{REQUEST_URI} !^/content_includes/
RewriteCond %{REQUEST_URI} !^/common_includes/
RewriteCond %{REQUEST_URI} !^/user_includes/
RewriteCond ${ADA_SITE_ROOT}/skeleton-pages/index%{ENV:WARPDEV}.shtml -f
RewriteRule . ${ADA_SITE_ROOT}/skeleton-pages/index%{ENV:WARPDEV}.shtml [L,E=X_ADA_PRODUCT:%1,E=X_ADA_PROFILE:%2,E=STATUS:product,E=X_ADA_PROFILETYPE:1]

RewriteCond %{REQUEST_URI} ^/userSettings/renderAll/([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9.-]+)\/?$
RewriteCond ${ADA_SITE_ROOT}/skeleton-pages/settings%{ENV:WARPDEV}.shtml -f
RewriteRule . ${ADA_SITE_ROOT}/skeleton-pages/settings%{ENV:WARPDEV}.shtml [L,E=X_ADA_VAR:renderAll,E=X_ADA_USER:%1,E=X_ADA_PRODUCT_TAG:%2,E=X_ADA_PRODUCT_IDTEMPLATE:%3,E=X_ADA_USER_DOMAIN:%4,E=STATUS:product]

RewriteCond %{REQUEST_URI} !^/personalizations/(.*)?$
RewriteCond %{REQUEST_URI} !^/userSettings/renderAll/(.*)$
RewriteCond %{REQUEST_URI} ^/userSettings/([A-Za-z0-9_]+)/([A-Za-z0-9]+)\/?([A-Za-z0-9_]*)\/?$
RewriteCond ${ADA_SITE_ROOT}/skeleton-pages/settings%{ENV:WARPDEV}.shtml -f
RewriteRule . ${ADA_SITE_ROOT}/skeleton-pages/settings%{ENV:WARPDEV}.shtml [L,E=X_ADA_VAR:%1,E=X_ADA_USER:%2,E=X_ADA_OTHERVAR:%3,E=STATUS:product]

RewriteCond %{REQUEST_URI} !^/personalizations/(.*)?$
RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9]+)\/?$
RewriteCond %{REQUEST_URI} !^/content_includes/
RewriteCond %{REQUEST_URI} !^/common_includes/
RewriteCond %{REQUEST_URI} !^/user_includes/
RewriteCond %{REQUEST_URI} !^/userSettings/
RewriteCond ${ADA_SITE_ROOT}/skeleton-pages/index%{ENV:WARPDEV}.shtml -f
RewriteRule . ${ADA_SITE_ROOT}/skeleton-pages/index%{ENV:WARPDEV}.shtml [L,E=X_ADA_PRODUCT:%1,E=X_ADA_PROFILE:NOCONTENT,E=STATUS:product]

RewriteCond %{HTTP:X_ADA_INTERNAL} ^$
RewriteCond %{ENV:STATUS} !^product$
RewriteCond %{ENV:WARPTARGET} !^_json
RewriteCond %{REQUEST_URI} ^/content_includes/ [OR]
RewriteCond %{REQUEST_URI} !^/common_includes/ [OR]
RewriteCond %{REQUEST_URI} ^/user_includes/
RewriteRule . ${ADA_SITE_ROOT}/www/NO_CONTENT.shtml [L]

AliasMatch ^/(content_includes|common_includes|user_includes)/(.*) ${ADA_SITE_ROOT}/www/$1/$2
