大网数据广告活动
服务器运维问答

Apache reverse proxy based on header

· 52CE 我爱测

So I have a configuration for apache that is working in 99% of the cases. It is checking a header value in the request and based on that it is redirecting to the correct API version url with a 307 status. This works for all clien…

问题原文

原帖链接 · munHunger · CC BY-SA 4.0

So I have a configuration for apache that is working in 99% of the cases. It is checking a header value in the request and based on that it is redirecting to the correct API version url with a 307 status. This works for all clients that properly implement the http stack. unfortunately I have an app that doesn't follow this and converts all POST requests into GET.

So this is the proxy.conf that I got right now:

RewriteEngine On
RewriteCond %{HTTP:X-Android-Version} =660
RewriteRule ^/services/6/(.*)$ /services/internal/6/$1 [R=307]

RewriteCond %{HTTP:X-Android-Version} >661
RewriteRule ^/services/6/(.*)$ /services/internal/7/$1 [R=307]


ProxyPass /services/internal/7 http://mbe700:8080/services/6
ProxyPass /services/internal/6 http://mbe600:8080/services/6

So what I am wondering is:

Is it possible to the same sort of proxypass without using a URL rewrite rule, since that doesn't really work in my case?

已采纳解答

原帖链接 · munHunger · CC BY-SA 4.0

Turns out this was way easier than I imagined... just changing the flag on the rewriterule seems to have done the trick.

RewriteEngine On
RewriteCond %{HTTP:X-Android-Version} =660
RewriteRule ^/services/6/(.*)$ /services/internal/6/$1 [P]

RewriteCond %{HTTP:X-Android-Version} >661
RewriteRule ^/services/6/(.*)$ /services/internal/7/$1 [P]


ProxyPass /services/internal/7 http://mbe700:8080/services/6
ProxyPass /services/internal/6 http://mbe600:8080/services/6

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-05-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。