<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Redirect index.html or index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.(php|html?)\sHTTP/
    RewriteRule ^ %1 [R=301,L]

    # Ensure the request isn't for an existing file or directory
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Route all other requests to index.php
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mime_module>
    AddType application/x-httpd-php .php
</IfModule>

# Protect .env and other sensitive files
<FilesMatch "^\.env|\.git|composer\.(json|lock)|artisan|server\.php|.htaccess">
    Order allow,deny
    Deny from all
</FilesMatch>
