<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 1. 如果访问的是 /about,且服务器存在 about.html,则自动映射
# 但不要在浏览器地址栏改变 URL(保持无后缀状态)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^/]+)$ $1.html [L]
# 2. 如果访问的是具体的 .html 文件(如 about.html),强制跳转到无后缀版本
# 这样可以统一 URL 规范,有利于 SEO
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
# 3. 你的原有单页应用路由逻辑(针对不存在的文件)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L,QSA]
</IfModule>