Forum Discussion

Shay_Ben-David1's avatar
Shay_Ben-David1
Icon for Nimbostratus rankNimbostratus
Jun 25, 2007

http code 301&302

when using irule to redirect example: "HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] "

 

i can see in the client that i get HTTP code 302 that means redirects, is there a way to get Permanent Redirect with HTTP 301 ?

 

thanks

 

 

2 Replies

  • Hi Shay,

     

     

    You can specify the response code with HTTP::respond (Click here). Here is an example:

     

     

    
    HTTP::respond  [content ] [ ]+

     

     

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

     

     

    Aaron
  • Here are a couple of examples:

    
     This will take requests for mydomain.com/$uri and 301 to www.mydomain.com/$uri
    switch -glob [string tolower [HTTP::host]] {
     "mydomain.com" {
      HTTP::respond 301 \
      "Location" "http://www.mydomain.com[HTTP::uri] " \
      "Server" "www.mydomain.com"
     }
    }
     This will 301 everone trying to access the /admin utilities to the homepage
    switch -glob [string tolower [HTTP::uri]] {
     "/admin/*" { 
      HTTP::respond 301 \
      "Location" "http://www.mydomain.com" \
      "Server" "www.mydomain.com"
     }
    }