Forum Discussion

Hamster_2020's avatar
Hamster_2020
Icon for Nimbostratus rankNimbostratus
Nov 19, 2013

HTTP to HTTP 301 Redirect with URI

At present I have the following irule:

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "domain.co.uk"} {

 

HTTP::respond 301 Location "http://www.domain.co.uk/"

 

}

 

}

 

Which seems to work but redirects all matching traffic to the root of http://www.domain.co.uk/. What I need is an irule that brings the URI in the request into the 301 response.

 

So I wonder whether the following would work:

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "domain.co.uk"} {

 

HTTP::respond 301 Location "http://www.domain.co.uk[HTTP::uri]"

 

}

 

}

 

4 Replies

  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus

    Try this:

    when HTTP_REQUEST {
     if { [HTTP::host] equals "domain.co.uk" } {
       HTTP::respond 301 Location "http://[getfield [HTTP::host] : 1][HTTP::uri]"
       }
      }
    

    See this wiki for details: link text

    Hope this helps,

    N

    • nathe's avatar
      nathe
      Icon for Cirrocumulus rankCirrocumulus
      No probs, let us know if it works if you can
  • I tried the suggestion and it didn't work - but the one I proposed worked just fine.

     

    Thanks again.