Forum Discussion

Andrea_Knapp_28's avatar
Andrea_Knapp_28
Icon for Nimbostratus rankNimbostratus
Oct 19, 2007

REdirect HTTP -> HTTPS based on IP

In Version 4.5 I had a simple rule that went as follows:

 

 

if (server_addr == 11.11.11.11) {

 

redirect to "https://www.yourdomain.com/%u"

 

}

 

else {

 

discard

 

}

 

 

So this would redirect any url that came in with IP address of 11.11.11.11 and forced it to change the URL to the new name. So if I typed http://yourdomain.com it would force it to https://www.yourdomain.com.

 

 

With V9 I am having issues having the same affect. I have the following:

 

 

when HTTP_REQUEST { if { [HTTP::host] eq "11.11.11.11" } {HTTP::redirect "https://www.yourdomain.com[HTTP::uri]"} else { discard }}

 

 

 

Now this only works if you enter the physical IP address. However if you enter the URL for this it does not work, it just spins.

 

 

I also havce changed it to:

 

 

when HTTP_REQUEST { if { [HTTP::host] eq "www.yourdomain.com" } {HTTP::redirect "https://www.yourdomain.com[HTTP::uri]" } else { discard }}

 

 

Any suggestions how I can force this by ready the IP that comes so I do not have to write multiple lines for each URL that I want to force that uses that same IP address.

 

 

Thank you,

 

Andrea

 

1 Reply

  • Hi,

    What exactly are you trying to accomplish? I'm guessing you had the 4.5 rule listed above configured on an HTTP virtual server with an IP of 11.11.11.11. You were using that rule to redirect all requests made via HTTP to HTTPS. Is this accurate?

    If so, you can use this rule to do the same in 9.x:

    
    when HTTP_REQUEST {
      HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }

    Aaron