简体   繁体   中英

http request forwarding according to the http header in apache

I have an apache server that gets http requests with 3 different headers. Depending on the header, I have to send it to backend servers.

Url : abc.com/check

Headers :

"Content-Type: app1"

"Content-Type: app2"

"Content-Type: app3"

Depending on the above header , the request has to be sent to backend app servers .

server1 : http://server1/s1 if "Content-Type: app1"

server2 : http://server1/s2 if "Content-Type: app2"

server3 : http://server1/s3 if "Content-Type: app3"

Please help me out .

Thanks.

I figured it out .Below snippet works our requirement. Some enhancements I'm thinking is to allow only POST requests .

<VirtualHost abc.com:80>
       ServerName abc.com

     RewriteEngine On
     RewriteCond %{HTTP:Content-Type} "app1"
     RewriteRule ^/check http://server1/s1 [P,L]

     RewriteCond %{HTTP:Content-Type} "app2"
     RewriteRule ^/check http://server1/s2 [P,L]

     RewriteCond %{HTTP:Content-Type} "app3"
     RewriteRule ^/check http://server1/s3 [P,L]

</VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM