Forum Discussion

KYENTURK_139771's avatar
KYENTURK_139771
Icon for Nimbostratus rankNimbostratus
Jul 08, 2014

URL Redirect with variable

Hello All,

 

We want to redirect source URL to Target URL at below but there is critical point for this URL. this string (.*) have to be end of the target URL. Can you share any example , solution or KB like as this problem.

 

Waiting your response and it is very urgent.

 

Problem: Source URL: http://abc.com/sample/abc.* (.* ) variable target : http://redirect.def.com/redirect/abc.*

 

5 Replies

  • This might work for you. I've not tried it but it should be a good starting point.

     

    when HTTP_REQUEST { if { [HTTP::host] equals "abc.com" } { if [HTTP::path] starts_with "/sample/abc"} {

     

    HTTP::redirect "http://redirect.def.com/redirect/abc[string range [HTTP::uri] 11 end]" } }

     

  • Hi again, Our source and target link below and you can see my irule. I think my problem start after ? query How can i configure irule after ? query. Is this irule work?

     

    Source http://test.abc.com/xyz/aa/srt/rfc/rc/TST_Z_WS_PORTAL?xyz-client=010&xyz-user=wsuser&xyz-password=sm3jl6qc3dr

     

    Target http://xyztstr.abc.com:8010/xyz/aa/srt/rfc/rc/Z_WS_PORTAL_EMTIA?xyz-client=010&xyz-user=wsuser&xyz-password=sm3jl6qc3dr

     

    when HTTP_REQUEST { if { [HTTP::path] starts_with "/xyz/aa/srt/rfc/rc/TST_Z_WS_PORTAL? } { HTTP::redirect "http://xyztstr.abc.com:8010/xyz/aa/srt/rfc/rc/Z_WS_PORTAL_EMTIA? [HTTP::query]" } }

     

  • Looks okay to me.

     

    Try putting " after your first line after the ?

     

    when HTTP_REQUEST { if { [HTTP::path] starts_with "/xyz/aa/srt/rfc/rc/TST_Z_WS_PORTAL?" } { HTTP::redirect "http://xyztstr.abc.com:8010/xyz/aa/srt/rfc/rc/Z_WS_PORTAL_EMTIA?[HTTP::query]" } }

     

  • Hi Again

     

    We tried this irule and it looks redirect correctly but we have another issue like below

     

    We will replace linux based reverse proxy to F5 and we don't want to see redirection url on browser, It will be show source url on browser but bring the target url ( Linux based reverse proxy works like this )

     

    I think we need to write rewrite rule but i don't know how can i write this rule

     

    Please could you help me for this situation

     

    For more details you can see below,

     

    Linux based reverse proxy config example

     

    RewriteRule ^/sap/bc/srt/rfc/sap/TST_TEST_KONTROL(.*) http://tstrestr.abc.com:8011/sap/bc/srt/rfc/sap/TEST_KONTROL$1 [P,L]

     

    RewriteRule ^/sap/bc/srt/rfc/sap/TST_TEST_CHANGE(.*) http://tstrestr.abc.com:8011/sap/bc/srt/rfc/sap/TEST_CHANGE$1 [P,L]

     

    In this rule

     

    ^ = http://test.abc.com

     

    (.*) = whatever comes put after $1

     

    (?sap-client=010&sap-user=wsuser&sap-password=sm3abcde1fg)

     

    It will going below site but can't change url link on browser http://tstrestr.abc.com:8011/sap/bc/srt/rfc/sap/TEST_KONTROL?sap-client=010&sap-user=wsuser&sap-password=sm3abcde1fg

     

    Regards

     

  • Take a look at the ProxyPass iRule.

     

    This is good for modifying hostnames and URI paths with reference to data groups.