Forum Discussion

Vivek_Padale_16's avatar
Vivek_Padale_16
Icon for Nimbostratus rankNimbostratus
Aug 13, 2014

I want to redirection from 302 to 301 through irule

Hello,

 

I want to do redirection from 302 to 301. for that i am using the below irule.

 

when HTTP_REQUEST { HTTP::respond 301 "Location" "http://[HTTP::host][HTTP::uri]" }

 

I want to know whether the irule is correct or not.

 

In my lab i don't have the resources to check whether the irule is working fine or not.

 

12 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Vivek,

     

    That's a valid iRule, syntax wise. However, you're only redirecting a client back to the same Host/URI combo? I would understand better if you were changing the protocol i.e. http to https.

     

    N

     

  • Hello Nathan,

     

    Thanks for the response.

     

    So as per the irule, when user types the URL in the browser will he get the 301 response?

     

  • So as per the irule, when user types the URL in the browser will he get the 301 response?

    yes. what nathan is asking is why you redirect to the exact same url.

    // config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        vs-index 65
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      HTTP::respond 301 "Location" "http://[HTTP::host][HTTP::uri]"
    }
    }
    
    // test
    
    [root@ve11a:Active:In Sync] config  curl -I http://172.28.24.10/something
    HTTP/1.0 301 Moved Permanently
    Location: http://172.28.24.10/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
    • lorvain's avatar
      lorvain
      Icon for Nimbostratus rankNimbostratus
      Hi, is it possible to personnalize header : "Server: BigIP" ? thanks
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      Why Irules add Server Header in HTTP::respond and HTTP::redirect https://devcentral.f5.com/s/feed/0D51T00006j3E1QSAU
  • So as per the irule, when user types the URL in the browser will he get the 301 response?

    yes. what nathan is asking is why you redirect to the exact same url.

    // config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        vs-index 65
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      HTTP::respond 301 "Location" "http://[HTTP::host][HTTP::uri]"
    }
    }
    
    // test
    
    [root@ve11a:Active:In Sync] config  curl -I http://172.28.24.10/something
    HTTP/1.0 301 Moved Permanently
    Location: http://172.28.24.10/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
    • lorvain's avatar
      lorvain
      Icon for Nimbostratus rankNimbostratus
      Hi, is it possible to personnalize header : "Server: BigIP" ? thanks
    • nitass_89166's avatar
      nitass_89166
      Icon for Noctilucent rankNoctilucent
      Why Irules add Server Header in HTTP::respond and HTTP::redirect https://devcentral.f5.com/s/feed/0D51T00006j3E1QSAU
  • Hello Nitass,

     

    Thanks for that. If i redirect to the exact same url will it cause any affects?

     

    Thank you

     

  • Hii Guys,

     

    Will the below irule also do the redirection to 301 :-

     

    HTTP::respond 301 "Location" "https://[HTTP::host][HTTP::uri]" } }

     

    Thanks.

     

  • Hello Guys,

     

    Regarding the redirection from 302 to 301 irule, in my environment there is also a http to https redirection irule in the same virtual server. So when i am applying this irule "when HTTP_REQUEST { HTTP::respond 301 "Location" "http://[HTTP::host][HTTP::uri]" } }" i am not able to redirect the site to 301 status. Please guys help me with the solution.