# 青笺 (Verda) 伪静态规则（Apache）
# 需要服务器开启 mod_rewrite 且站点目录 AllowOverride All
<IfModule mod_rewrite.c>
    RewriteEngine On

    # 根路径：交由 index.php 动态处理（双语模式 301 → /cn/，纯中文模式直接渲染）
    RewriteRule ^$ index.php [L,QSA]

    # 语言前缀 /cn（中文） /en（英文）—— 与无前缀规则结构一致，仅多一层前缀
    RewriteRule ^(cn|en)/post/([0-9]+)/?$          post.php?p=$2&lang=$1       [L,QSA]
    RewriteRule ^(cn|en)/post/(.+)/?$              post.php?slug=$2&lang=$1    [L,QSA]
    RewriteRule ^(cn|en)/category/(.+)/?$          category.php?c=$2&lang=$1   [L,QSA]
    RewriteRule ^(cn|en)/page/(.+)/?$              page.php?p=$2&lang=$1       [L,QSA]
    RewriteRule ^(cn|en)/tag/(.+)/?$               tag.php?t=$2&lang=$1        [L,QSA]
    RewriteRule ^(cn|en)/tags/?$                   tags.php?lang=$1             [L,QSA]
    RewriteRule ^(cn|en)/archives/([0-9]+)\.html$  post.php?p=$2&lang=$1        [L,QSA]
    RewriteRule ^(cn|en)/archive/?$                archive.php?lang=$1          [L,QSA]
    RewriteRule ^(cn|en)/search/?$                 search.php?lang=$1           [L,QSA]
    RewriteRule ^(cn|en)/sitemap\.xml$             sitemap.php?lang=$1          [L,QSA]
    RewriteRule ^(cn|en)/feed/?$                   feed.php?lang=$1             [L,QSA]
    RewriteRule ^(cn|en)/?$                         index.php?lang=$1            [L,QSA]
    # html 模式：{slug}.html → slug.php 分派器（区分文章/独立页面）
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(cn|en)/([^./]+)\.html$           slug.php?slug=$2&lang=$1    [L,QSA]
    # 通用回退
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(cn|en)/(.+)/?$                   $2?lang=$1                   [L,QSA]

    # 无前缀（兼容旧链接 / 直链，默认中文）
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^post/([0-9]+)/?$        post.php?p=$1       [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^post/(.+)/?$            post.php?slug=$1    [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^category/(.+)/?$        category.php?c=$1   [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^tag/(.+)/?$             tag.php?t=$1        [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^tags/?$                 tags.php            [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^page/(.+)/?$            page.php?p=$1       [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^archive/?$              archive.php         [L,QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^search/?$               search.php         [L,QSA]
    RewriteRule ^sitemap\.xml$           sitemap.php         [L,QSA]
    RewriteRule ^feed/?$                 feed.php             [L,QSA]
    # html 模式（无前缀）
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^./]+)\.html$         slug.php?slug=$1    [L,QSA]
</IfModule>
