# Deeniyat Plus deep links on admin.deenlearning.in
#
# Source of truth: cx-deeniyat-plus-backend-api/deeplinks/  (runbook: docs/2026-09-22_deep_links.md)
# Deployed to /srv/deeplinks/ and pulled in with ONE line as the FIRST line inside the
# admin.deenlearning.in <VirtualHost *:443>, above every other directive:
#
#     Include /srv/deeplinks/apache-deeplinks.conf
#
# Apache has no inline comments: keep every comment on its own line.

# The admin panel is a React SPA whose catch-all serves index.html for unknown paths.
# A vhost-level RewriteRule runs before Alias, so let our paths through first.
# "-" means no substitution: mod_rewrite declines and the Alias lines below map the request.
# END also stops any per-directory (.htaccess) rewrite from touching them afterwards.
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule "^/\.well-known/(?:assetlinks\.json|apple-app-site-association)$" - [END]
    RewriteRule "^/DeeniyatPlus(?:/.*)?$" - [NC,END]
</IfModule>

# Exact files only. Never map the whole /.well-known/ prefix: certbot's acme-challenge lives there.
Alias      "/.well-known/assetlinks.json"            "/srv/deeplinks/assetlinks.json"
Alias      "/.well-known/apple-app-site-association" "/srv/deeplinks/apple-app-site-association"
# /DeeniyatPlus, /DeeniyatPlus/ and /DeeniyatPlus/anything (any case) get the fallback page.
# /DeeniyatPlusXYZ does not match and still goes to the admin SPA.
AliasMatch "(?i)^/DeeniyatPlus(?:/.*)?$"             "/srv/deeplinks/DeeniyatPlus.html"

<Directory "/srv/deeplinks">
    Options None
    AllowOverride None
    Require all granted

    # Apache 2.4 sends no Content-Type for an extensionless file. Serve the AASA as JSON.
    # (assetlinks.json already gets application/json from mime.types.)
    <Files "apple-app-site-association">
        ForceType application/json
    </Files>

    <IfModule mod_headers.c>
        <FilesMatch "^(?:assetlinks\.json|apple-app-site-association)$">
            Header set Cache-Control "public, max-age=3600"
        </FilesMatch>
        <Files "DeeniyatPlus.html">
            Header set Cache-Control "no-cache"
        </Files>
    </IfModule>
</Directory>
