# ==========================================================================
# sinsiu2 Apache 配置（伪静态 + 目录保护 + 安全头）
# 放在站点根目录。使用 Nginx 时请参考 nginx.conf.example
# ==========================================================================

# 目录列表关闭
Options -Indexes

# 默认入口
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 禁止直接访问敏感目录（data 存数据库、config 存密码、app 是代码、tests 是自检、plugins 是插件源码）
    RewriteRule ^(data|config|app|tests|plugins)(/|$) - [F,L]

    # 真实存在的文件 / 目录直接放行（CSS、JS、上传图片、admin.php 等）
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # ---------- 前台伪静态 ----------
    RewriteRule ^cat/([^/]+)/page/([0-9]+)$ index.php?r=cat&slug=$1&page=$2 [L,QSA]
    RewriteRule ^cat/([^/]+)$ index.php?r=cat&slug=$1 [L,QSA]

    RewriteRule ^a/([0-9]+)-([^/]+)\.html$ index.php?r=article&id=$1&slug=$2 [L,QSA]
    RewriteRule ^a/([0-9]+)\.html$ index.php?r=article&id=$1 [L,QSA]

    RewriteRule ^tag/([^/]+)/page/([0-9]+)$ index.php?r=tag&slug=$1&page=$2 [L,QSA]
    RewriteRule ^tag/([^/]+)$ index.php?r=tag&slug=$1 [L,QSA]

    RewriteRule ^search$ index.php?r=search [L,QSA]
    RewriteRule ^archive/([0-9]{4})$ index.php?r=archive&year=$1 [L,QSA]
    RewriteRule ^archive$ index.php?r=archive [L,QSA]
    RewriteRule ^p/([^/]+)$ index.php?r=page&slug=$1 [L,QSA]

    RewriteRule ^rss\.xml$ index.php?r=rss [L,QSA]
    RewriteRule ^sitemap\.xml$ index.php?r=sitemap [L,QSA]
    RewriteRule ^robots\.txt$ index.php?r=robots [L,QSA]
</IfModule>

# ---------- 静态资源缓存 ----------
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 7 days"
    ExpiresByType application/javascript "access plus 7 days"
    ExpiresByType image/jpeg "access plus 30 days"
    ExpiresByType image/png "access plus 30 days"
    ExpiresByType image/webp "access plus 30 days"
    ExpiresByType image/gif "access plus 30 days"
    ExpiresByType image/svg+xml "access plus 30 days"
</IfModule>

# ---------- 安全响应头 ----------
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# 默认 UTF-8
AddDefaultCharset UTF-8

# 隐藏 PHP 版本
<IfModule mod_php.c>
    php_flag expose_php off
</IfModule>
