【问题标题】:Apache 2.4 strip query parameter and add that as a headerApache 2.4 剥离查询参数并将其添加为标头
【发布时间】:2019-01-09 12:20:35
【问题描述】:

我有以下网址 -

http://ip:8080/dashboard/db/testdash?id=add&t1=abc

我想从 url 中删除 t1 并将其作为标头添加到我的代理请求中。我有工作反向代理 conf,我想截取这个 url 去掉 t1 参数并将其添加为将发送到目的地的标头

我的虚拟主机在 8080 上监听有以下配置

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)t1=(.*)
>>>Need to add the rewrite logic here
>>>Add rewrite conf here change url to /dashboard/db/testdash?id=add

//Add the request header 
>>>RequestHeader set X-T1 "value of the query parameter"

//Proxy 
ProxyRequests Off
ProxyPass "/" http://localhost:3000/
ProxyPassReverse "/" http://localhost:3000/

Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "*"

# Added a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]

我对 httpd 完全陌生,所以不知道该怎么做!

【问题讨论】:

    标签: apache mod-rewrite apache2.4


    【解决方案1】:
    • 删除ProxyPass,因为我们要使用变量
    • 添加RewriteRule (^/.*) http://localhost:3000/$1?%1

      注意,如果 URL 最后可以有更多的键,这种匹配是不够的!更强大的正则表达式只会通过捕获 & 来吞噬 t1 值。例如^(.*)t1=([^&].*)(.*) 然后替换 %1%3

    • 添加一个古怪的空白部分来弥补被删除的ProxyPass

    <Proxy http://localhost:3000/ >
    
    </Proxy>
    

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多