Forum Discussion

kmtmt_51646's avatar
kmtmt_51646
Icon for Nimbostratus rankNimbostratus
Apr 17, 2012

change http:/ links to https:/ except a certain URL

Hi all, Servers have HTML links with a href tag with "http:" so I use stream iRules to change them to "https:" but now I need to not change it for a certain URL. I'd like to do: 1) check server response and rewrite HTML links from http:/ to https:/ 2) if the link is www.no-change.com , do not rewrite and keep it http:/ Attached file is what I wrote but not working... Does anyone have any ideas for help? Thank you, kmtmt

5 Replies

  • can you try something like this?

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          stream {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b pool foo list
    pool foo {
       members 200.200.200.101:80 {}
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       STREAM::disable
    }
    when HTTP_RESPONSE {
       if {[HTTP::header value Content-Type] contains "text"}{
          STREAM::expression {@http://www.no-change.com/@http://www.no-change.com/@@http://@https://@}
          STREAM::enable
       }
    }
    }
    
    [root@ve1023:Active] config  curl http://200.200.200.101/test.html
    ...snipped...
    http://www.no-change.com/something
    http://www.change.com/something
    ...snipped...
    
    [root@ve1023:Active] config  curl http://172.28.19.79/test.html
    ...snipped...
    http://www.no-change.com/something
    https://www.change.com/something
    ...snipped...
    

    LTM stream profile: Multiple replacements & regular expressions by Deb

    https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/101/LTM-stream-profile-Multiple-replacements-regular-expressions.aspx
  • I like that idea of finding/replacing the same string to avoid the replacement Nitass. Here's another option using a lookaround regex:

    
    when HTTP_REQUEST {
        Disable the stream filter for all requests
       STREAM::disable
    }
    when HTTP_RESPONSE {
    
        Check if response type is text
       if {[HTTP::header value Content-Type] contains "text"}{
    
           Replace any http:// instance with https://, unless the original string is http://www.no-change.com
          STREAM::expression {@http:(?!//www\.no-change\.com)@https://@}
    
           Enable the stream filter for this response only
          STREAM::enable
       }
    }
    

    Aaron
  • Hi nitass, hoolio

     

     

    It worked perfectly!

     

    Thank you, really appreciate it!

     

     

     

    Best Regards,
    • aandreyy_293459's avatar
      aandreyy_293459
      Icon for Nimbostratus rankNimbostratus

      hi

      i also want to do the same and exclude from changing to https but when i modify iRule with

      if {[HTTP::header value Content-Type] starts_with "text"} {

         STREAM::expression {@http:(?!//www\.w3\.org)@https://@}
      

      from STREAM::expression {@@}

      page not loading at all, getting errors like "ERR_CONNECTION_RESET" "secure connections failed". Not sure what can cause this?

    • aandreyy_293459's avatar
      aandreyy_293459
      Icon for Nimbostratus rankNimbostratus

      strange that after adding config STREAM::expression {@http:(?!//@} VIP not responding at all (did various configurations ). I can see than that browser not getting response at all while everything should work as before. Also i can see on iRule statistics numbers increasing. Can it be related with SW (11.6.1 build 2.0.338)? or something else?

       

      Maybe someone can suggest use other regular expressions to do the same?

       

      thanks