# ============================================================================
# CACHING, SECURITY, AND COMPRESSION
# ============================================================================

# [cc] 2026-06-13 — Static-asset caching + compression for cold-load performance.
# NOTE: This file was CREATED (no prior .htaccess existed in this docroot). It contains
# ONLY caching/compression headers — no URL-rewrite rules. If app rewrite rules are ever
# added, APPEND them; do not let this block clobber them.

# --- Far-future cache for fingerprinted / static assets ---------------------
# All asset URLs in this app are cache-busted with ?<filemtime> query strings,
# so a far-future immutable cache is safe: a changed file gets a new ?mtime and
# is re-fetched automatically. mod_headers is required (loaded on this server).
<IfModule mod_headers.c>
	<FilesMatch "\.(png|jpe?g|gif|svg|ico|css|js|woff2?|ttf|eot)$">
		Header set Cache-Control "public, max-age=31536000, immutable"
	</FilesMatch>
</IfModule>

# --- Fisiere care nu trebuie servite niciodata prin web ----------------------
# [cc] 2026-08-09 — gasit pe v33.s4t.ro: https://<tenant>/inc/configuration.ini
# raspundea 200 si scotea in clar host/username/password/database. Nu era ceva
# ce am stricat noi (aceeasi situatie inainte de deploy, .htaccess-ul identic
# octet cu octet) — pur si simplu nimic nu proteja inc/. Pe instalarile criptate
# fisierul e cifrat, deci nu se citea; pe cele necriptate se citea intreg.
# Blocam si arhivele: un backup lasat in radacina (_dg.tar) se putea descarca.
# [cc] 2026-09-07 - .json adaugat: temporary/ tine applied.json si markerul de identitate al agentului de hotfix (cheia HMAC de raportare), iar regula veche mergea doar pe extensie.
# [cc] 2026-08-20 - fisiere de depanare care tiparesc configul (deci si parola bazei).
# get_configuration.php era un fisier uitat de 5 randuri, fara nicio autentificare;
# l-am scos din kit, iar regula asta il opreste si daca reapare vreodata pe disc.
<FilesMatch "^get_configuration\.php$">
	Require all denied
</FilesMatch>
<IfModule !mod_authz_core.c>
	<FilesMatch "^get_configuration\.php$">
		Order allow,deny
		Deny from all
	</FilesMatch>
</IfModule>

<FilesMatch "\.(ini|tar|tar\.gz|tgz|sql|log|json)$">
	Require all denied
</FilesMatch>
<IfModule !mod_authz_core.c>
	<FilesMatch "\.(ini|tar|tar\.gz|tgz|sql|log|json)$">
		Order allow,deny
		Deny from all
	</FilesMatch>
</IfModule>

# --- Gzip compression for text assets ---------------------------------------
# Guarded: if mod_deflate is not loaded (e.g. default XAMPP), this block is a
# harmless no-op. On production Apache (mod_deflate present) it compresses text.
<IfModule mod_deflate.c>
	AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
	AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
	AddOutputFilterByType DEFLATE application/json application/xml
	AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>

# ============================================================================
# URL REWRITING AND API ROUTING 
# ============================================================================

<IfModule mod_rewrite.c>
	RewriteEngine On

	# Pass the HTTP Authorization header to the environment
	RewriteCond %{HTTP:Authorization} ^(.*)
	RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

	# Route all /api/* requests to api/index.php, EXCEPT the system connector
	RewriteCond %{REQUEST_URI} !/api/system/connector\.php$ [NC]
	RewriteRule api/(.*)$ api/index.php?url=$1 [QSA,L]
</IfModule>
