Apache .htaccess
Nginx 配置
转换在浏览器本地完成,配置内容不会上传。
使用须知
- 结果是起点,不是成品。Apache 与 Nginx 的重写模型有本质差异:Apache 的
.htaccess 按目录逐层生效并可多轮循环匹配,Nginx 的 rewrite 在 server / 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 块。
- 无法自动转换的指令(如
AuthType、php_value、SetEnvIf、复杂的 RewriteMap)会原样注释保留,并在下方列出提示。
- Nginx 里
last 相当于 Apache 的 [L],permanent 对应 [R=301],redirect 对应 [R=302],break 用于停止继续重写。
- 相关:Robots 生成、htpasswd 生成、正则测试、GZIP 压缩检测。