# =========================================================
# .htaccess - SMK SMF INDONESIA  (letakkan di folder utama web / public_html; juga jalan di subfolder/localhost)
# =========================================================
Options -Indexes
RewriteEngine On

# ---------------------------------------------------------
# 1. Hapus ekstensi .php dari alamat (redirect permanen 301)
#    /sejarah.php -> /sejarah   |   /index.php -> /
#    Hanya untuk GET/HEAD agar form (POST) tidak rusak.
# ---------------------------------------------------------
RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
RewriteCond %{THE_REQUEST} \s\S*index\.php[\s?] [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
RewriteCond %{THE_REQUEST} \s\S+\.php[\s?] [NC]
RewriteCond %{REQUEST_URI} ^(.+)\.php$ [NC]
RewriteRule ^ %1 [R=301,L,NE]

# ---------------------------------------------------------
# 2. Sitemap untuk Google: /sitemap.xml
# ---------------------------------------------------------
RewriteRule ^sitemap\.xml$ sitemap.php [L]

# ---------------------------------------------------------
# Favicon: /favicon.ico -> assets/images/logo/favicon.ico
# ---------------------------------------------------------
RewriteRule ^favicon\.ico$ assets/images/logo/favicon.ico [L]

# ---------------------------------------------------------
# 3. Alamat berita
#    /berita/judul-berita -> detail_berita.php?slug=judul-berita
#    /berita              -> berita.php
# ---------------------------------------------------------
RewriteRule ^berita/([A-Za-z0-9_-]+)/?$ detail_berita.php?slug=$1 [L,QSA]
RewriteRule ^berita/?$ berita.php [L,QSA]

# ---------------------------------------------------------
# 4. Alamat tanpa .php (juga untuk folder admin)
#    /sejarah -> sejarah.php   |   /admin/list_berita -> admin/list_berita.php
# ---------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L,QSA]
