# ============================================================
# SoSite / FlintHub — Apache 伪静态重写（根目录 .htaccess）
# 与 nginx-server.conf 规则等价，供 Apache 环境使用：
#   1. 伪静态：非真实文件/目录请求统一转发到前端控制器 index.php 路由
#   2. 敏感目录防护：data/ protected/ cli/ 及插件数据目录禁止 Web 访问
#   3. 上传目录禁止 PHP 执行（纵深防御）
# 注意：.htaccess 仅对 Apache + AllowOverride FileInfo/Indexes 生效。
#       若本站为 Nginx（phpstudy 常用），请忽略本文件，规则已由 nginx-server.conf 配置。
# ============================================================

<IfModule mod_rewrite.c>
    RewriteEngine On

    # ----------------------------------------------------------
    # 1. 敏感目录禁止直接访问（对应 nginx location ^/(data|protected|cli)/）
    #    返回 403 Forbidden
    # ----------------------------------------------------------
    RewriteRule ^(?:data|protected|cli)(?:/|$) - [F,L]

    # 插件数据目录禁止直接访问（对应 nginx ^/plugins/[^/]+/data/）
    RewriteRule ^plugins/[^/]+/data(?:/|$) - [F,L]

    # 上传目录禁止 PHP 执行（纵深防御；对应 nginx ^/assets/uploads/.*\.php$）
    RewriteRule ^assets/uploads/.*\.php$ - [F,L]

    # ----------------------------------------------------------
    # 2. /repo/ 仓库浏览路由：非真实文件统一转发到前端控制器
    #    （对齐 nginx location ^~ /repo/ try_files $uri /index.php）
    # ----------------------------------------------------------
    RewriteCond %{REQUEST_URI} ^/repo/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # ----------------------------------------------------------
    # 3. 常规伪静态：非真实文件/目录 → index.php/路径（前端控制器路由）
    #    （对齐 nginx rewrite ^/(.*)$ /index.php/$1 last）
    #    Apache 内部 rewrite 保留 REQUEST_URI，Router 由 REQUEST_URI 分发，无需额外处理
    # ----------------------------------------------------------
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

# 禁止目录列表
Options -Indexes

# 默认编码
<IfModule mod_charset.c>
    AddDefaultCharset UTF-8
</IfModule>

# [PWA 2026-08-21] .webmanifest MIME 映射（Apache 双轨；Nginx 侧见 nginx-server.conf types 块）
AddType application/manifest+json .webmanifest