Linux环境下RewriteEngine多场景配置故障排查求助
正常运行场景
192.168.1.10x 段IP重写
需求:仅对192.168.1.100-109段IP生效,将http://192.168.1.2:81/api?key=value重写为http://192.168.1.3:8080/api?key=value
配置代码:RewriteCond %{SERVER_PORT} =81 RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.10[0-9]$ RewriteRule ^ http://192.168.1.3:8080/api192.168.1.15x 段IP重写
需求:仅对192.168.1.150-159段IP生效,将http://192.168.1.2:81/api?key=value重写为http://192.168.1.4:8080/api?key=value
配置代码:RewriteCond %{SERVER_PORT} =81 RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.15[0-9]$ RewriteRule ^ http://192.168.1.4:8080/api
异常问题场景
192.168.1.10x 段IP重写丢失请求路径
期望:仅对192.168.1.100-109段IP生效,将http://192.168.1.2:80/my/fancy/folder/myFile.json重写为http://192.168.1.3:80/my/fancy/folder/myFile.json
实际问题:仅重定向到http://192.168.1.3:80,丢失请求路径
错误配置代码:RewriteCond %{SERVER_PORT} =80 RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.10[0-9]$ RewriteRule ^ http://192.168.1.3:80192.168.1.15x 段IP重写丢失请求路径
期望:仅对192.168.1.150-159段IP生效,将http://192.168.1.2:80/my/fancy/folder/myFile.json重写为http://192.168.1.4:80/my/fancy/folder/myFile.json
实际问题:仅重定向到http://192.168.1.4:80,丢失请求路径
错误配置代码:RewriteCond %{SERVER_PORT} =80 RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.15[0-9]$ RewriteRule ^ http://192.168.1.4:80
内容的提问来源于stack exchange,提问作者balumba

