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....
  • Dvirus_297774's avatar
    Jan 05, 2017

    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" 
        }
     }