4

I need to set up reverse proxy which will put header value from original request as a parameter to the destination url. The reason for this is purelly application specific and unfortunatelly I cannot change this application. For example I need the folowing https://a.com with http header myparam=abcd i need to be proxied to http://b.com/?val=abcd

Is it possible to configure IIS or Apache to perform such task ? If so, can you explain how ?

2
  • I see you unaccepted my answer and did not accept the other answer. Are you still looking for answers / more details? If not, you should accept one of the answers.
    – user49740
    May 4, 2015 at 15:19
  • 1
    @user49740 No, just forgot to mark :) May 4, 2015 at 18:52

2 Answers 2

2
+50

Tested in Apache 2.4:

# (In a VirtualHost for a.com)
RewriteEngine on
RewriteRule ^(.*)$ http://b.com$1?val=%{HTTP:myparam} [QSA,P]

Example rewrites (if the header myparam has value myvalue):

  • a.com becomes http://b.com?val=myvalue
  • a.com/path/here becomes http://b.com/path/here?val=myvalue
  • a.com/path?a=b&c=d becomes http://b.com/path?a=b&c=d&val=myvalue

If the myparam header does not exist, a.com/x will redirect to http://b.com/x?val=. If you want to redirect to http://b.com/x, you can use the following longer version of the above:

RewriteEngine on
RewriteCond %{HTTP:myparam} .
RewriteRule ^(.*)$ http://example.com$1?val=%{HTTP:myparam} [QSA,L,P]
RewriteRule ^(.*)$ http://example.com$1 [P]

Related links:

1

For IIS you could use the URL Rewrite extension :

IIS URL Rewrite 2.0 enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find. By using rule templates, rewrite maps, .NET providers, and other functionality integrated into IIS Manager, Web administrators can easily set up rules to define URL rewriting behavior based on HTTP headers, HTTP response or request headers, IIS server variables, and even complex programmatic rules. In addition, Web administrators can perform redirects, send custom responses, or stop HTTP requests based on the logic expressed in the rewrite rules.

Works With: IIS 7, IIS 7.5, IIS 8

A walkthrough can be found on : Creating Rewrite Rules for the URL Rewrite Module.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .