<IfModule mod_rewrite.c>
    RewriteEngine On

    # dataフォルダへの直接アクセスを403 Forbiddenにする
    RewriteRule ^data/ - [F,L]

    # 実在するファイル・ディレクトリはそのまま通す
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # --- パーマリンク ルーティング ---

    # 基本: /?p=123
    RewriteRule ^$ index.php [L,QSA]

    # 数字および英数字ベース (IDがハッシュ化されている場合に対応): /archives/123a4b
    RewriteRule ^archives/([a-zA-Z0-9_-]+)/?$ index.php?post_id=$1 [L,QSA]

    # カテゴリーアーカイブ: /category/slug
    RewriteRule ^category/([^/]+)/?$ index.php?category=$1 [L,QSA]

    # 日付＋投稿名: /2026/06/12/slug
    RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/([^/]+)/?$ index.php?slug=$4&year=$1&monthnum=$2&day=$3 [L,QSA]

    # 月＋投稿名: /2026/06/slug
    RewriteRule ^([0-9]{4})/([0-9]{2})/([^/]+)/?$ index.php?slug=$3&year=$1&monthnum=$2 [L,QSA]

    # 投稿名 (プレーン): /slug
    RewriteRule ^([^/]+)/?$ index.php?slug=$1 [L,QSA]

</IfModule>