RewriteEngine On
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# Entry points must be revalidated so they never reference a retired asset
# graph. Hashed assets can remain cached; their filenames are build-unique.
Header always set Cache-Control "no-cache, no-store, must-revalidate"
Header always set Pragma "no-cache"
Header always set Expires "0"
# The PWA worker must be fetched from the site root and must not be rewritten
# into the PHP API. Its scope depends on this exact URL remaining accessible.
Require all granted
ForceType application/javascript
RewriteRule ^sw\.js$ - [L]
# ALIAS: Silently map any request to /solidmark/api/* to the /backend/ folder
RewriteCond %{REQUEST_URI} ^/solidmark/api/(.*)$
RewriteRule ^(.*)$ backend/%1 [L,QSA]
# Backward compatibility for cached frontend builds that used
# /solidmark/backend/api/*. Remove after all clients receive the new build.
RewriteCond %{REQUEST_URI} ^/solidmark/backend/api/(.*)$
RewriteRule ^(.*)$ backend/%1 [L,QSA]
# 3 levels with .php
RewriteRule ^api/([^/]+)/([^/]+)/([^/]+)\.php/?$ backend/$1/$2/$3.php [L,QSA]
# 3 levels without
RewriteRule ^api/([^/]+)/([^/]+)/([^/]+)/?$ backend/$1/$2/$3.php [L,QSA]
# 2 levels with .php
RewriteRule ^api/([^/]+)/([^/]+)\.php/?$ backend/$1/$2.php [L,QSA]
# 2 levels without
RewriteRule ^api/([^/]+)/([^/]+)/?$ backend/$1/$2.php [L,QSA]
# 1 level with .php
RewriteRule ^api/([^/]+)\.php/?$ backend/$1.php [L,QSA]
# 1 level without
RewriteRule ^api/([^/]+)/?$ backend/$1.php [L,QSA]
# Automatically append .php if accessing /backend/ directly without the extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^backend/(.*)$ backend/$1.php [L,QSA]
# SPA fallback: serve index.html for any route that doesn't match a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.html [L]