0

i am trying to write two rewrite rules which are PASS THROUGH or PROXY so that i can hide the underlying url.

Case1:

When a request comes to app.domain.com/folder1/folder2/ it should go through a.b.mydomain.com/folder1/folder2/ what ever comes after folder2 in app.domain.com/folder1/folder2/ should be added to a.b.mydomain.com/folder1/folder2/ after folder 2.

Example app.domain.dom/folder1/folder2/search/?q=test should be passed through a.b.mydomain.com/folder1/folder2/search/?q=test

Case2:

When a request comes to company1.app.domain.com/folder1/folder2/ it should go through company1.a.b.mydomain.com/folder1/folder2/

This company1 may be varying i should be able to fetch it dynamically and append to the second url.

what ever comes after folder2 in company1.app.domain.com/folder1/folder2/ should be added to company1.a.b.mydomain.com/folder1/folder2/ after folder 2.

Example

company1.app.domain.com/folder1/folder2/search/?q=test should be passed through company1.a.b.mydomain.com/folder1/folder2/search/?q=test

I have tried to write the following :

One rule:

RewriteRule ^([A-Za-z0-9-]+).app.domain.com\/folder1\/folder2\/$  http://%1.a.b.mydomain.com/folder1/folder2/$1 [PT]

and another one i tried

RewriteCond %{HTTP_HOST} ^([a-z0-9]+).app.domain.com
RewriteRule ^services/v1/(.*) http://%1.a.b.xyz.com/services/v1/$1 [P]

Some how both of the trials havenot work, Please help me.. thanks

1 Answers1

0

The following rules solved the problem

Case 1:

RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteRule ^/services/v1/(.*)$ http://a.b.xyz.com/services/v1/$1 [P,L]

The above rule checks the condition http_host == app.domain.com then pattern in request uri starts with /services/v1/ and after v1 whatever comes captured with (.*) and it is appended at the last with $1

Case 2:

RewriteCond %{HTTP_HOST} (.*)\.app.domain.com$
RewriteRule ^/services/v1/(.*)$ http://%1.a.b.xyz.com/services/v1/$1 [P,L]

The above rule checks the condition http_host == *. app.domain.com then pattern and captures it in %1 and applies the rule when request uri starts with /services/v1/ and after v1 whatever comes captured with (.*) and it is appended at the last with $1

P flag for proxy and L flag for last line