You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux环境下RewriteEngine多场景配置故障排查求助

Apache 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/api
    
  • 192.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:80
    
  • 192.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 17:53:08