Forum Discussion

dwhite12_255934's avatar
dwhite12_255934
Icon for Nimbostratus rankNimbostratus
Jan 05, 2017

Assistance with iRule for substitue/redirect - LTM

Web developer would like this behavior:

 

so if a GET request is made to 'testsite2.com/unsubscribe.php[?params&params]' it should be forwarded to https://testsite2.com/testapp/unsubs/unsubscribe.php[?params&params]

 

Tried this with a variation of a previous DevCentral response:

 

when HTTP_REQUEST { if { ([HTTP::host] eq "testsite2.com") and ([string tolower [HTTP::uri]] ends_with "/unsubscribe.php") } { HTTP::respond 308 Location "; } }

 

Seems to be resulting in a 404 when parameters are supplied stating: /unsuscribe.php (The requested resource is not available)

 

Thanks in advance,

 

Doug

 

  • Hi,

    what will happen if you directly went to this?

     http://testsite2.com/testapp/unsubs/unsubscribe.php
    

    try this:

    when HTTP_REQUEST {
        if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } {
            HTTP::respond 301 noserver Location "/testapp/unsubs/unsubscribe.php"
        }
     }
    

    OR

    when HTTP_REQUEST {
        if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } {
            HTTP::redirect "http://testsite2.com/testapp/unsubs/unsubscribe.php"
        }
     }
    

    SELECTED ANSWER - This will keep your parameters and will only replace the url:

    when HTTP_REQUEST {
        if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } {
            set uri [string map {"/unsubscribe.php" "/testapp/unsubs/unsubscribe.php"} [HTTP::uri]] 
            HTTP::redirect "http://[HTTP::host]$uri" 
        }
     }
    
  • Hi,

    what will happen if you directly went to this?

     http://testsite2.com/testapp/unsubs/unsubscribe.php
    

    try this:

    when HTTP_REQUEST {
        if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } {
            HTTP::respond 301 noserver Location "/testapp/unsubs/unsubscribe.php"
        }
     }
    

    OR

    when HTTP_REQUEST {
        if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } {
            HTTP::redirect "http://testsite2.com/testapp/unsubs/unsubscribe.php"
        }
     }
    

    SELECTED ANSWER - This will keep your parameters and will only replace the url:

    when HTTP_REQUEST {
        if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } {
            set uri [string map {"/unsubscribe.php" "/testapp/unsubs/unsubscribe.php"} [HTTP::uri]] 
            HTTP::redirect "http://[HTTP::host]$uri" 
        }
     }