Forum Discussion

Scott_85950's avatar
Scott_85950
Icon for Nimbostratus rankNimbostratus
Nov 13, 2010

Root Domain Redirect Retaining Query String

Hi, I am looking to redirect, hopefully 301 redirect, from the default domain when called to a new home page location while retaining any appended query in the original URI. I have the following iRule created, which does work, but the query is not retained when redirected. Please help! .

 

 

when HTTP_REQUEST {

 

set my_uri [HTTP::uri]

 

set my_query [HTTP::query]

 

if { ([HTTP::host] eq "mysite.com") } {

 

switch -glob [HTTP::uri] {

 

"/" { HTTP::redirect "http://[HTTP::host]/guest/en/home.shtml$my_query" }

 

}

 

}

 

}

 

6 Replies

  • Expected behavior:

     

     

    www.mysite.com/?s_cid=ThisIsATest --> www.mysite.com/guest/en/home.shtml?s_cid=ThisIsATest
  • what about this one?

    
    when HTTP_REQUEST {
        if { [HTTP::path] equals "/" } {
                  HTTP::redirect "http://[HTTP::host]/guest/en/home.shtml?[HTTP::query]" }
        }
     }
    
  • i a little bit modified rule according to sol9952. pls feel free to revise.

    SOL9952: The HTTP::path iRule command may return more information than expected

    https://support.f5.com/kb/en-us/solutions/public/9000/900/sol9952.html

    
    virtual bar {
       snat automap
       pool foo
       destination 172.28.17.55:80
       ip protocol 6
       rules myredirect
       profiles {
          http {}
          tcp {}
       }
    }
    rule myredirect {
       when HTTP_REQUEST {
            if { [URI::path [HTTP::path]] eq "/" and [HTTP::query] ne ""} {
                    HTTP::redirect "http://[HTTP::host]/guest/en/home.shtml?[HTTP::query]"
            }
    }
    }
    

    
     curl -I http://172.28.17.55
    HTTP/1.1 200 OK
    Date: Sat, 13 Nov 2010 07:28:33 GMT
    Server: Apache/2.0.59 (rPath)
    Last-Modified: Thu, 11 Nov 2010 04:23:21 GMT
    ETag: "1315d-5f-5580a040"
    Accept-Ranges: bytes
    Content-Length: 95
    Content-Type: text/html; charset=UTF-8
    
     curl -I http://172.28.17.55/?s_cid=ThisIsATest
    HTTP/1.0 302 Found
    Location: http://172.28.17.55/guest/en/home.shtml?s_cid=ThisIsATest
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
  • Thank you, this works great. I am going to slightly modify with the following for a 301 redirect. As well, thank you for the information on the limitation of the URI:path prefix in SOL9952. I believe for our application of this iRule, I don't foresee this as a problem, but will test to be sure.

     

     

    when HTTP_REQUEST {

     

    if { [URI::path [HTTP::path]] eq "/" and [HTTP::query] ne ""} {

     

    HTTP::respond 301 "Location" "http://[HTTP::host]/guest/en/home.shtml?[HTTP::query]"

     

    }

     

    }
  • Update; with further testing, we found that there were JavaScript errors generated by new queries being added to the URL when navigating in the site. We've further revised the iRule and are testing again to verify conflicts.

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::path] eq "/" and [HTTP::query] ne ""} {

     

    HTTP::respond 301 "Location" "http://[HTTP::host]/guest/en/home.shtml?[HTTP::query]"

     

    }

     

    }