# ============================================================================
#  .htaccess untuk WordPress - ikipie.com
#  Simpan sebagai:  public_html/.htaccess
#
#  PERHATIAN: kalau ada .htaccess lama, SALIN/backup dulu sebelum menimpa.
#  Berkas ini yang membuat "permalink" (URL cantik) tidak 404.
# ============================================================================

# --- 1. Memaksa HTTPS (aktifkan SETELAH SSL Let's Encrypt terbit) -----------
# Kalau SSL belum aktif dan blok ini dipasang, situs malah tidak bisa dibuka.
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

# --- 2. Lindungi berkas sensitif --------------------------------------------
<FilesMatch "^(wp-config\.php|\.htaccess|\.env|readme\.html|license\.txt)$">
    Require all denied
</FilesMatch>

# --- 3. Cegah daftar isi folder ---------------------------------------------
Options -Indexes

# --- 4. Aturan WordPress (WAJIB - sumber 404 kalau hilang) ------------------
# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# ============================================================================
#  CATATAN
#  - Blok BEGIN/END WordPress di atas JANGAN diubah manual; biarkan WordPress
#    yang menulisnya lewat Settings > Permalinks (tombol Save).
#  - Kalau situs masih 404 padahal .htaccess sudah benar:
#      1) pastikan Apache punya mod_rewrite (tanyakan Rumahweb)
#      2) cPanel > MultiPHP INI Editor: AllowOverride harus memperbolehkan FileInfo
#      3) Settings > Permalinks > Save Changes (ini yang memicu WP menulis ulang)
# ============================================================================
