Forum Discussion

Ashu_2116's avatar
Ashu_2116
Icon for Nimbostratus rankNimbostratus
Jul 05, 2017

http redirect i-rule under https VS not working

Hi I am new to i-rule writing. I have 4 urls hosted on one web server. And web server is front ended by Big IP LTM for ssl offloading. Now i want my urls to redirect to /directory when accessing it with a general url address. I have configured the http and https VS and clientssl profile and in normal conditions (without i-rule) the urls works perfectly. So if i access the url https://abc.bbc.com/mydirectory/ it works perfectly but when i access https://abc.bbc.com (when i-rule applied) it redirects to https://abc.bbc.com/mydirectory/ (i can observe in browser) but output with error "page can't be displayed"

 

Strange is that when i apply the same i-rule to http VS the url works but when i apply the i-rule to https VS the url stop working. The configuration on http and https vs is almost same other than clientssl profile.

 

I-rule applied to http & https VS :

 

when HTTP_REQUEST { if { [string tolower [HTTP::host]] contains "abc.bbc.com" } { HTTP::redirect https://abc.bbc.com/mydirectory/ } }

 

So above i-rule works with http VS but not with https VS.I also tried using switch statements but no luck :(

 

Thanks !!

 

6 Replies

  • P_K's avatar
    P_K
    Icon for Altostratus rankAltostratus

    Try just adding the iRule to HTTPS VIP and apply HTTPs redirect iRule (inbuilt irule name -> _sys_https_redirect) to HTTP VIP. Also check if removing the trailing slash (mydirectory/) works.

     

    • Stanislas_Piro2's avatar
      Stanislas_Piro2
      Icon for Cumulonimbus rankCumulonimbus

      NAG zzz

       

      I think this code will help Ashu, but there is no need to convert uri to lowercase to compare it with / . lowercase and uppercase of / is still / 🙂

       

      when HTTP_REQUEST { 
          if { [string tolower [HTTP::host]] contains "abc.bbc.com" and [HTTP::uri] equals "/"} { 
              HTTP::redirect /mydirectory/ 
          }
      }
      

      @Ashu, don't use the same irule on both virtual servers.

       

      • on HTTP VS, use the default sys_https_redirect
      • on HTTPS VS use this irule

      You will have 2 redirect if user requests http://abc.bbc.com/ but transparent for user.

       

    • Ashu_2116's avatar
      Ashu_2116
      Icon for Nimbostratus rankNimbostratus

      Thanks a lot Stanislas Piron !! The i-rule is working like a charm. Thanks again for your help !!

       

      I have 3 more urls hosted on same webserver and they also require similar redirection. Can these other three urls redirections be clubbed into this i-rule or i have to write a separate i-rule for each of them ?

       

      def.bbc.com points to https://def.bbc.com/yourdirectory ghi.bbc.com points to https://ghi.bbc.com/newdirectory jkl.bbc.com points to https://jkl.bbc.com/olddirectory

       

      Also May i ask the difference between your code and my code? It will help me understanding & learning the i-rule code and future i-rule writing.

       

  • You can use this irule

    when HTTP_REQUEST { 
        if { [HTTP::uri] equals "/"} {
            switch [string tolower [HTTP::host]] {
                "abc.bbc.com" {HTTP::redirect /mydirectory/}
                "def.bbc.com" {HTTP::redirect /yourdirectory/}
                "ghi.bbc.com" {HTTP::redirect /newdirectory/}
                "jkl.bbc.com" {HTTP::redirect /olddirectory/}
                default {HTTP::respond 403 {Bad Hostname}}
            }
        }
    }