首页 > 工具箱 > htaccess 转 Nginx

htaccess 转 Nginx 配置

Apache .htaccess

Nginx 配置

转换在浏览器本地完成,配置内容不会上传。

使用须知

  • 结果是起点,不是成品。Apache 与 Nginx 的重写模型有本质差异:Apache 的 .htaccess 按目录逐层生效并可多轮循环匹配,Nginx 的 rewriteserver / location 上下文中单轮执行。复杂规则务必人工复核后再上线。
  • 转换后请用 nginx -t 校验语法,再 nginx -s reload 生效。
  • 已支持:RewriteRule / RewriteCond(HTTP_HOST、HTTPS、REQUEST_FILENAME 的 -f/-d/-e、REQUEST_URI、QUERY_STRING、HTTP_REFERER、HTTP_USER_AGENT)、RewriteBase、Redirect / RedirectMatch、ErrorDocument、DirectoryIndex、Options -Indexes、Deny/Allow from、Header set/add、ExpiresByType、AddType、FilesMatch / Files 块、IfModule 块。
  • 无法自动转换的指令(如 AuthTypephp_valueSetEnvIf、复杂的 RewriteMap)会原样注释保留,并在下方列出提示。
  • Nginx 里 last 相当于 Apache 的 [L]permanent 对应 [R=301]redirect 对应 [R=302]break 用于停止继续重写。
  • 相关:Robots 生成htpasswd 生成正则测试GZIP 压缩检测