Forum Discussion

dundovic_25174's avatar
dundovic_25174
Icon for Nimbostratus rankNimbostratus
Jan 23, 2012

HTTP Class profile redirect

I understand this is iRule discussion forum and I can achieve this using iRule, but due to some specific customer requirements, they'd like to have it done using 'HTTP class' profile.

 

 

Following should explain the task.

 

 

Original URL:

 

 

http://Server1.domain1.com/Folder1/

 

 

Redirect to:

 

 

http://Server2.domain2.com/Folder2/

 

 

 

Basically, any request coming to 'server1' and 'Folder1' should be redirected to 'Server2'/'Folder2', but the rest of path should be retained. Could this be achieved using 'HTTP class' profile?

 

 

Thanks!

 

9 Replies

  • Seems like the rest of the path was removed...it should read:

     

     

    Original URL:

     

     

    http://Server1.domain1.com/Folder1/REST_OF_PATH

     

     

    Redirect to:

     

     

    http://Server2.domain2.com/Folder2/REST_OF_PATH
  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    Here is the config I used (output from tmsh):

    test-ltm-ve-03(Active)(/Common)(tmos) list ltm profile httpclass redirect_server1_to_server2

    ltm profile httpclass redirect_server1_to_server2 {

    app-service none

    defaults-from httpclass

    hosts { glob:Server1.domain1.com }

    paths { glob:/Folder1 }

    pool none

    redirect http://Server2.domain2.com/Folder2/

    }

    Keep in mind that the matches are case sensitive, so if you are expecting different capitalization, you might want to use a regex (slower). Hope that helps,

    -George

  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    Hi dundovic,

     

     

    I don't think you can use regex matches within HTTP class profiles. If you want match and replace, you'll have to use an iRule here.

     

     

    -George
  • Thanks for your suggestions, George. I'll try to find out if HTTP class can be somehow used in this scenario, otherwise, I'll have to proceed with an iRule, which was my original idea.

     

     

    Regards,

     

     

    S.

     

  • As Michael showed, you can use iRule commands in the Redirect to Location field. So you can append the current URI using [HTTP::uri]. If you want to substitute a string (Folder1) for another (Folder2) within the URI, you could use:

     

     

    http://server2.domain3.com[string map {Folder1 Folder2} [HTTP::uri]]

     

     

    Aaron
  • Thanks all! I appreciate your help. I didn't know iRule commands could be mixed with the field entries.

     

     

    Regards,

     

     

    S.
  • How would you use the Headers -> Header List to redirect based on the value of a header? How do you specify the header and the expected value? Can you write: X-Roles="admin", for example, as a matching condition? I'm not sure I understand the intent of headers in the HTTP Class Profile dialog pictured above.

     

     

    Thanks!
  • Hi Curtis,

     

     

    The header field of an HTTP class is checked against each HTTP header line. If you want to match just a header name, you could set the Headers field to "header-name:" without the quotes. If you want to match a specific header name and value, you can set the Headers field to "header-name: header-value" without the quotes. If you want to perform a case-insensitive match, you can use a regex instead of a string pattern and use the (?i) token:

     

     

    (?i)header-name: header-value

     

     

    Aaron