# ---------------------------------------------------------------------------
# ISRC.in - web root (cPanel: public_html, or public_html/<folder> for a
# staging sub-domain). The application itself is in ./isrc_app/ (private).
# ---------------------------------------------------------------------------
Options -Indexes
ServerSignature Off
AddDefaultCharset UTF-8

# Never serve hidden files, backups, logs or database dumps that may be copied here by mistake.
<IfModule mod_authz_core.c>
    <FilesMatch "(^\.|\.(env|sql|log|bak|old|orig|swp|ini|sh|lock|dist)$|~$|^(spark|composer\.(json|lock)|phpunit\.xml\.dist|preload\.php)$)">
        Require all denied
    </FilesMatch>
</IfModule>

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # The application folder (isrc_app) must never be served. It also has its
    # own deny-all .htaccess; this rule is a second, independent lock.
    RewriteRule ^isrc_app(/|$) - [F,L,NC]

    # If the site lives in a sub-folder (e.g. https://example.org/isrc-staging/),
    # uncomment and set:
    # RewriteBase /isrc-staging/

    # Redirect trailing slashes (except directories) to the canonical URL
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Canonical host: www.isrc.in -> isrc.in (HTTPS is enforced by the application)
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

    # Send requests for anything that is not a real file to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

    # Pass the Authorization header to PHP
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

# Compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/xml application/javascript application/json image/svg+xml
</IfModule>

# Browser caching for static assets (URLs carry a ?v= version, so long lifetimes are safe)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
</IfModule>
