cancel
Showing results for 
Search instead for 
Did you mean: 

Redirecting URI and Dynamic Content

marv_Williams_5
Nimbostratus
Nimbostratus

I am struggling to get this to work. Here is the scenario:

 

https://mycompany.com/virtual.aspx?code=....&type=....

 

Redirect to:

 

https://egift.mycompany.com/egift.aspx?eid=.....&tid=.......

 

Any help would be appreciated

 

22 REPLIES 22

DevBabu
Cirrus
Cirrus

what would be the value for eid and tid ?

 

marv_Williams_5
Nimbostratus
Nimbostratus

The only values that are the same are the eid and tid. everything else is dynamic

 

marv_Williams_5
Nimbostratus
Nimbostratus

Let me try this again: Client enters https://mycompany.com/virtual.aspx we want to redirect to: https://egift.mycompany.com/virtual.aspx?code=.......&type=......

 

When I try to redirect based on URI the dynamic portion is cutoff. I need to pass the entire URI and dynamic content also

 

Kevin_Stewart
F5 Employee
F5 Employee

How are you doing it now? If you're using HTTP::path to evaluate the URI, that will indeed ignore the query string portion of the URI.

 

marv_Williams_5
Nimbostratus
Nimbostratus

I was using HTTP path and the uri virtual.aspx to redirect

 

marv_Williams_5
Nimbostratus
Nimbostratus

Here is the I-Rule I initially came up with to redirect but it was chopping off the dynamic content

 

when HTTP_REQUEST { set uri [HTTP::uri] set host [HTTP::host] if { "$uri" contains "/egift" } { HTTP::redirect "https://egiftpp.mycompany.com/$uri" } }

 

DevBabu
Cirrus
Cirrus
can this be done this way when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "mycompany.com" } { if {[HTTP::query] != ""} { HTTP::respond 302 Location "https://egiftpp.mycompany.com[HTTP::path]?[HTTP::query]" } else { HTTP::respond 302 Location "https://egiftpp.mycompany.com[HTTP::path]" } } }

Stanislas_Piro2
Cumulonimbus
Cumulonimbus

Hi,

 

If I understand what you want in the first question:

 

  • hostname is replaced from mycompany.com to egift.mycompany.com
  • path must be replaced from /virtual.aspx to /egift.aspx
  • parameter code is stripped

after some added information, you only change hostname... can you explain each part that must be changed.

 

DevBabu
Cirrus
Cirrus

Will the value of eid and tid changes during redirection or remains same ?

 

for example.

 

Original Request https://123.mycompany.com/egift.aspx?eid=abc123&tid=def123 Is this Redirection: https://456.mycompany.com/egift.aspx?eid=abc123&tid=def123 or it has a different value https://456.mycompany.com/egift.aspx?eid=pqr123&tid=xyz123

Opher_Shachar_6
Nimbostratus
Nimbostratus

Can I make a suggestion?

 

Assuming you're running a recent BigIP version, that is v11.4.0 and above, why not use a LTM Policy to do the job?

 

Opher_Shachar_6
Nimbostratus
Nimbostratus

Thats what a LTM Policy would look like:

 

ltm policy mycompany.com_policy { controls { forwarding } requires { http } rules { egift { actions { 0 { http-reply redirect location https://456.mycompany.com[HTTP::uri] } } conditions { 0 { http-host host values { 123.mycompany.com } } 1 { http-uri path values { /egift.aspx } } } ordinal 1 } } strategy first-match }

I agree with you, policy is the easiest solution to redirect, assign pools, rewrite headers... The problem is the irule does exactly the same as your policy and does not solve the issue. that's why I asked marv Williams to explain what are differences between the initial request and the redirect URL.

The values and placement of tid and eid chnage. I was hoping at least tid and eid would remain static. The request uses a number that the user has and they enter the entire url with the dynamic number. The redirect then contains new dynamic information after egift.aspx?. Also I am using 11.5.0 currently and did not think of policy but could try it

I mean dynamic content which is a series of letters and numbers

Further clarification: - hostname changes from mycompany.com to egift.mycompany.com - uri remains egift.aspx all the way through -user enters dynamic content in the request (mycompany.com/egift.aspx?eid=xxxxxxx&tid=xxxxxxx and the is then redirected with new dynamic content. ex: egift.mycompany.com/egift.aspx?eid=a&tid=b Hope this makes sense?

No. Doesn't make sense ... it's not clear who (or what) computes the new values of *eid* and *tid* from the old values.

Stanislas_Piro2
Cumulonimbus
Cumulonimbus

Hi,

 

You can use this irule to help you:

 

when HTTP_REQUEST { if { ([string tolower [HTTP::host]] equals "mycompany.com") && ([HTTP::path] equals "/egift.aspx" ) } { set eidval [URI::query [HTTP::uri] eid] set tidval "b" HTTP::respond 302 Location "https://egiftpp.mycompany.com[HTTP::path]?eid=$eidval&tid=$tidval" } }

As you can see, you can parse previous query to get parameters values and assign to parameters in redirect.

 

marv_Williams_5
Nimbostratus
Nimbostratus

I have tried to get the redirect to work without any success. Here is a better idea of what we are trying to redirect and the I-Rule I have used:

 

Here is what we are trying to do: 1.) https://www.mysite.com/egift.aspx?eid=&tid= - to be re-routed to https://egift.mysite.com/egift?eid=&tid=

 

Here is the I-Rule I used to attempt the redirect:

 

when HTTP_REQUEST { log local0. "Request [URI::query [HTTP::uri]eid]" if { ([string tolower [HTTP::host]] equals "mysite.com") && ([HTTP::path] equals "/egift.aspx" ) } { set eidval [URI::query [HTTP::uri] eid] set tidval [URI::query [HTTP::uri] tid] Log local0. "Request [HTTP::path]" HTTP::respond 302 Location "https://redirectsite.com[HTTP::path]?eid=$eidval&tid=$tidval" } }

 

When I turned on logging I recieved this response: Mon Sep 14 21:20:52 PDT 2015 info sc-preprod-DMZ-lb tmm1[29803] Rule /Common/egift-redirect2 : Request:eid=DM67JKKM4DBLXPYDS88KDX8PL0&tid=VMH5N8QQJA87XCF6022YZHG724&template=basiceid

 

The above I-Rule looks like it should work but it does not redirect correctly

 

Stanislas_Piro2
Cumulonimbus
Cumulonimbus

Hi,

 

I tried the iRule and the I got the expected result:

 

$ curl -i "http://192.168.1.133/egift.aspx?eid=DM67JKKM4DBLXPYDS88KDX8PL0&tid=VMH5N8QQJA87XCF6022YZHG724&template=basiceid" -H "Host: mysite.com" HTTP/1.0 302 Found Location: https://redirectsite.com/egift.aspx?eid=DM67JKKM4DBLXPYDS88KDX8PL0&tid=VMH5N8QQJA87XCF6022YZHG724 Server: BigIP Connection: Keep-Alive Content-Length: 0

marv_Williams_5
Nimbostratus
Nimbostratus

Thanks, I will run another test and verify.

 

Shawn_Conway
Cirrus
Cirrus

We are trying something similar and was trying to edit what you have but could not figure it out.

 

We are trying to rewrite using id number which will change and would like to append it redirect site below. in this case it is "12677"

 

https://localsite.com/publications/citation.aspx?type=FN&PubId=12677&PersonId=109

 

redirect to:

 

https://redirectsite.com/publicationid/12677

 

What do you think?

 

Thanks!!

 

funduval
Nimbostratus
Nimbostratus

Hi I'm kind of surprised there's no simple answer for this.

We need to redirect (also see requirements below):

https://foo.bar.com/authorize/aaa/bbb/someFile.jsp?response_type=<some_dynamic_value>&client_id=<some_dynamic_value>&scope=<some_dynamic_value>&redirect_uri=<some_dynamic_value>

to 

https://xxx.baz.com/authorize/aaa/bbb/someFile.jsp?response_type=<same_dynamic_value_from_request>&client_id=<same_dynamic_value_from_request>&scope=<same_dynamic_value_from_request>&redirect_uri=<same_dynamic_value_from_request>

Requirement #1: we can't use pools or policies.

Requirement #2: Only change requests coming into the path that starts with /authorize (e.g. https://foo.bar.com/authorize/etc. gets redirected). Other requests hitting the host with a different start to the path must remain unchanged (e.g. https://foo.bar.com/billling must stay the same).

Requirement #2: With a simple redirect, we want to change the host name only, and keep the paths in the redirect  the same as in the request and keep all query params and their values in the redirect the same as in the request (values change dynamically with each request)