Forum Discussion

Albert__Tase_70's avatar
Albert__Tase_70
Icon for Nimbostratus rankNimbostratus
Aug 03, 2010

adding to a redirect

Hello need some help trying to grab a piece of the uri and append it to the redirect

 

 

for example user goes to www.bbb.com wants to get redirect via a 301 to https://bbb.com/yyyy and if the users adds

 

www.bbb.com/nnn they want to append that to the https://bbb.com/yyy/nnn got the basic syntax just cannot seem to figure out how to add the uri to the redirects uri for anything after the /yyy.

 

 

any Ideas ?

 

 

 

thanks

 

 

 

4 Replies

  • Hi Al,

     

     

    Are you wanting to parse the portion of the original request from the query string (like a parameter name and/or value) or part of the path?

     

     

    For an example URL, here are the different portions of the request:

     

     

    http://www.example.com/path/to/file.ext?param1=value1&param2=value2

     

     

    Host - [HTTP::host] = www.example.com

     

    Path - [HTTP::path] = /path/to/file.ext

     

    URI - [HTTP::uri] = /path/to/file.ext?param1=value1&param2=value2

     

    Query string = [HTTP::query] = param1=value1&param2=value2

     

    Query string parameter value = value1 and value2, use URI::query workaround to get the values (in pre-10.2 versions):

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/uri__query

     

     

    [URI::query "?&[HTTP::query] &param_name

     

     

    To further parse the path, you can use URI::path:

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/uri__path

     

     

    Aaron
  • I don't think user-agents will include anchors in the request sent to the web app. The browser should make a request using the URI minus the anchor and then use the anchor to go to a specific section in the page. You can test this by logging the HTTP::uri value for a request like https://www.example.com/xyx/trackingid=8888 and see if the URI is logged as / or /xyx/trackingid=8888.

     

     

    In concept though, you can send a 301 redirect using:

     

     

    HTTP::respond 301 Location "https://www.example.com/new_uri"

     

     

    Aaron
  • ok but how ?

     

     

    I would have to query the uri comming in and make it a varable quessing here

     

    but then how to add it to the HTTP::respond 301 Location "https://www.example.com/new_uri"

     

     

    because I need to redirect it to https://www.example.com/xyx no matter what and then add what ever is typed after

     

    the www.example.com to https:/www.example.com/xyx so if the users types www.example.com they get redirected via a 301 to https://www.example2.com/xyx if the users types www.example.com/trackingid=8888 they need to get redirected to https://www.eample2.com/xyx/trackingid=8888 this is so the app server can grep the id what ever it be and log it.

     

     

     

    so it would be an if else statement if http::host equals www.example.com

     

    http::respond 301 location "https://www.eaxmple2.com/xyx

     

    else

     

    http::response 301 location "https://www.example2.com/xyx/ whatever comes after the www.example.com

     

     

     

    the issue is that the /xyx is a;ready part of ther uri that I need to redirect to which I have to set on the lb then I need to add to it from whatever the user types as the uri after the www.example.com

     

     

    basically not sure how to do this if it can be done

     

     

    so if user a types www.example.com he needs to get redirected via 301

     

    to

     

    if user a types www.example.com/trackingid=8888 he needs to get redirected

     

    to 2.com/xyx/trackingid=8888

     

     

    in the second part the user can typ anying after the host the uri the user types needs to get preserved ansd added to

     

    the redirected uri /xyx/

     

     

     

     

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    It sounds like all you're trying to do is redirect to a second host name, preserving the URI, but making sure that no matter what the URI was, it starts with /xyz/ first. Your concern is that you don't want to end up with a URI that starts with /xyz/xyz/, right? A simple if clause will solve that problem for you.

    So I think what you're looking for is something like:

    
    when HTTP_REQUEST {
      if {[HTTP::uri] starts_with "/xyz" } {
        HTTP::redirect "http://example2.com[HTTP::uri]"
      } else {
        HTTP::redirect "http://example2.com/xyz[HTTP::uri]"
      }
    }

    Does that sound about right? If I missed something, let me know.

    Colin