Forum Discussion

Rob_Notaro_7816's avatar
Rob_Notaro_7816
Icon for Nimbostratus rankNimbostratus
Nov 08, 2007

Simple URL redirect

I just want a request from www1.company.com to redirect to www.company.com. I dont want to change anything that might be after the url.

 

 

Will this do the trick?

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "www1.company.com"} {

 

HTTP::header replace "Host" "www.company.com"

 

switch -glob [HTTP::uri]

 

}

1 Reply

  • Do you actually want to rewrite the Host header or send a 302 redirect back to the client with the updated URL?

    If you remove the switch command from your rule, you would successfully replace the Host header in the request sent to the web servers with the updated host value.

    If you wanted to redirect clients to the new host with the same URI, you can use this:

    
    when HTTP_REQUEST {
       if { [HTTP::host] equals "www1.company.com"} {
          HTTP::redirect http://www.company.com[HTTP::uri]
       }
    }

    Note that you should change http:// to https:// in the redirect if your VIP is using client SSL.

    Aaron