# Correct MIME type for the PWA manifest so browsers accept the install metadata
# (many hosts serve .webmanifest as text/plain, which Chrome rejects).
<IfModule mod_mime.c>
    AddType application/manifest+json .webmanifest
</IfModule>

# Long-lived caching for the immutable app icons (content-addressed by name).
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/x-icon "access plus 30 days"
</IfModule>

# The service worker must never be held in the HTTP cache, or a new release
# won't be picked up. (Browsers also byte-check it on navigation, but be explicit.)
<IfModule mod_headers.c>
    <Files "sw.js">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
    </Files>
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect direct requests to index.php to the base URL
    RewriteCond %{THE_REQUEST} \s/index\.php [NC]
    RewriteRule ^index\.php$ ./ [R=302,L]

    # If the requested file or directory exists, serve it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Otherwise, route everything to index.php
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

