# Galmudug CID - LiteSpeed/cPanel configuration

# Load the PHP login page when the domain root is opened.
DirectoryIndex index.php index.html

# Do not display directory contents when an index file is missing.
Options -Indexes

# Override any inherited rule that blocks all PHP files.
# This is required because the previous hosting rule returned 403 for every
# PHP page, including index.php, login.php and certificate.php.
<FilesMatch "\.(?:php[0-9]?|phtml|phar)$">
    Require all granted
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Block TRACE and TRACK requests.
    RewriteCond %{REQUEST_METHOD} ^(?:TRACE|TRACK)$ [NC]
    RewriteRule ^ - [F,L]

    # Prevent uploaded files from being executed as PHP scripts.
    RewriteRule ^uploads/.*\.(?:php[0-9]?|phtml|phar)$ - [F,L,NC]

    # Protect hidden files, while allowing SSL validation files.
    RewriteRule "(^|/)\.(?!well-known(?:/|$))" - [F,L]

    # Enable this only after AutoSSL is active for system.cid.gm.so.
    # RewriteCond %{HTTPS} !=on
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

# Block direct web access to application configuration files.
<FilesMatch "^(db|auth|config)\.php$">
    Require all denied
</FilesMatch>

# Block backups, database exports, logs, environment files and server configs.
<FilesMatch "(^\.env|\.(?:ini|log|sql|bak|backup|conf|dist|md|lock)$)">
    Require all denied
</FilesMatch>

# Block dependency manifests from public access.
<FilesMatch "^(?:composer\.(?:json|lock)|package(?:-lock)?\.json)$">
    Require all denied
</FilesMatch>

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set Referrer-Policy "same-origin"
    Header unset X-Powered-By
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/svg+xml "access plus 7 days"
    ExpiresByType image/png "access plus 7 days"
    ExpiresByType image/jpeg "access plus 7 days"
    ExpiresByType text/css "access plus 1 day"
    ExpiresByType application/javascript "access plus 1 day"
</IfModule>
