# Disable directory browsing
Options -Indexes

# Enable symbolic links and rewrite engine
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Force HTTPS redirect
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Redirect www to non-www
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

    # Remove trailing slash from URLs
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Rewrite everything else to framework's index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L,QSA]

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

# Fallback if mod_rewrite is not available
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /404.html
</IfModule>

# Hide Apache version info
ServerSignature Off

# PHP handler
<IfModule mime_module>
    AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>