<IfModule mod_rewrite.c>
    RewriteEngine On

    # 禁止直接访问敏感目录和文件（优先于路由）
    RewriteRule ^(config|vendor|cache|app)(/|$) - [F,L]
    RewriteRule ^(composer\.json|composer\.lock|\.git|\.gitignore|\.env)(|$) - [F,L]

    # 强制 HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # 统一到 www.china-speed-reducer.com
    RewriteCond %{HTTP_HOST} ^china-speed-reducer\.com$ [NC]
    RewriteRule ^(.*)$ https://www.china-speed-reducer.com/$1 [R=301,L]

    # 前端路由：非实际文件/目录且非 /admin 时转发到 index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/admin
    RewriteRule ^(.*)$ index.php [QSA,L]

    # 后台路由：/admin 且非实际文件/目录时转发到 admin.php
    RewriteCond %{REQUEST_URI} ^/admin
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^admin(/.*)?$ admin.php [QSA,L]
</IfModule>
