# ============================================================ # URL 重写规则 # 让 /phone/{model} 和 /history/{date} 这类动态路径 # 落到各自文件夹的 index.php 上处理 # ============================================================ RewriteEngine On # 1) 已存在的真实文件 / 目录不重写(图片、favicon、子目录的 index.php 等) RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # 2) /phone/{model} -> /phone/index.php # (/phone/search 和 /phone/all 是真实目录,已被上面规则放过) RewriteRule ^phone/([^/]+)/?$ /phone/index.php [L,QSA] # 3) /history/{date} -> /history/index.php RewriteRule ^history/([^/]+)/?$ /history/index.php [L,QSA] # 4a) /weather/auto -> /weather/auto.php(必须在通用城市规则之前,否则 auto 会被当成城市名) RewriteRule ^weather/auto/?$ /weather/auto.php [L,QSA] # 4b) /weather/{city} -> /weather/index.php # (/weather/ 和 /weather/?city= 直接命中目录的 index.php,无需重写) RewriteRule ^weather/([^/]+)/?$ /weather/index.php [L,QSA] # 5) /ip/{address} -> /ip/index.php # (/ip/ 和 /ip/?ip= 直接命中目录的 index.php,无需重写) RewriteRule ^ip/([^/]+)/?$ /ip/index.php [L,QSA] # 6) /hot/{source} -> /hot/index.php # (/hot/ 和 /hot/?source= 直接命中目录的 index.php,无需重写) RewriteRule ^hot/([^/]+)/?$ /hot/index.php [L,QSA] # 7) /mobile/{phone} -> /mobile/index.php RewriteRule ^mobile/([^/]+)/?$ /mobile/index.php [L,QSA] # 8) /zipcode/{code} -> /zipcode/index.php RewriteRule ^zipcode/([^/]+)/?$ /zipcode/index.php [L,QSA] # 9) /translate/{text} -> /translate/index.php RewriteRule ^translate/([^/]+)/?$ /translate/index.php [L,QSA] # 10) /baike/{keyword} -> /baike/index.php RewriteRule ^baike/([^/]+)/?$ /baike/index.php [L,QSA] # ============================================================ # 保护数据文件:禁止通过 HTTP 直接访问 .json / .html 模板 # ============================================================ Require all denied # 保护 common.php 不被直接访问 Require all denied # 保护 config.php 不被直接访问(含数据源配置) Require all denied # 默认字符集 AddDefaultCharset UTF-8 # 目录索引 DirectoryIndex index.php index.html