# =========================================================
# HADIRMU - URL TANPA EKSTENSI & KEAMANAN DASAR
# =========================================================

Options -Indexes -MultiViews

DirectoryIndex index.php index.html

# Lindungi file sensitif
<FilesMatch "(?i)(^\.|\.sql$|\.log$|\.ini$|\.env$|\.bak$|\.backup$|\.old$|\.orig$|\.save$|\.swp$|composer\.(json|lock)$|package(-lock)?\.json$)">
    Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Cegah folder internal dibuka langsung
    RewriteRule ^(?:config|vendor)(?:/|$) - [F,L,NC]

    # Ubah URL .php menjadi tanpa ekstensi
    # dashboard.php menjadi dashboard
    RewriteCond %{THE_REQUEST} \s/+(.+?)\.php(?:[\s?]) [NC]
    RewriteRule ^(.+?)\.php$ $1 [R=301,L,NE]

    # Ubah URL .html atau .htm menjadi tanpa ekstensi
    RewriteCond %{THE_REQUEST} \s/+(.+?)\.html?(?:[\s?]) [NC]
    RewriteRule ^(.+?)\.html?$ $1 [R=301,L,NE]

    # Biarkan file dan folder asli tetap berjalan
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Akses file PHP tanpa ekstensi
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/?$ $1.php [L,QSA]

    # Akses file HTML tanpa ekstensi
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteRule ^(.+?)/?$ $1.html [L,QSA]
</IfModule>