Forum Discussion

Heidi_35827's avatar
Heidi_35827
Icon for Nimbostratus rankNimbostratus
Nov 08, 2011

iRule for HTTP redirect from retired URL to new URL

I'm new to iRules and could use some help. I think I have a pretty basic question but I'm not finding the answer after a few searches in DevCentral.

 

 

Here is what I'm trying to do....we have a web site that is retiring and will be replaced with a new site. We would like to do an http redirect to the new site when someone hits the old URL. Both sites are HTTPS. We want the URL in the users address bar to change to the new address.

 

 

Basic functionality: User goes to https://www.oldsite.com. Redirect is sent to send user to https://www.newsite.com

 

 

I've tried some basic HTTP redirect iRules, but none are working for me.

 

 

Do I need to use something other than a basic HTTP profile in the vserver I'm applying the iRule to?

 

 

Is the HTTPS adding some complexity that I'm not accounting for?

 

 

 

 

 

 

 

19 Replies

  • If you don't want the /survey-soutions URI, then don't add the [HTTP::uri] string at the end of the HTTP::respond command.
  • In these examples we always see that you use the old site as a reference. What if you simply want to say. "Anything that comes to this address" forward to this URL.

     

     

    Thanks
  • That's the very basis of the built-in HTTP-to-HTTPS iRule. It simply redirects without a conditional expression.
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    Try this:

    HTTP::respond 301 Location [string replace [HTTP::host] 0 3 "abc."][HTTP::uri] 
  • just another example.

    e.g.

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       if { [HTTP::host] starts_with "www" } {
          HTTP::respond 301 noserver Location "http://[string map {www abc} [HTTP::host]][HTTP::uri]"
       }
    }
    }
    [root@ve10:Active] config  curl -I http://www.foo.com/something
    HTTP/1.0 301 Moved Permanently
    Location: http://abc.foo.com/something
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve10:Active] config 
    
  • Dear Team,

     

     

    I require one redirection rule for below requirement.

     

    1) http://example.in

     

    2) http://www.example.in

     

    3) https://www.example.in

     

     

    to http://home.example.co.in

     

     

    i have below iRule

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::host]] contains "example.in" } {

     

    HTTP::redirect "http://home.example.co.in"

     

    }

     

    }

     

     

    will it work, or do have to made any changes in it.

     

     

    Ashish Takawale.
  • will it work, or do have to made any changes in it.yes, it could work. if you want more specific, switch case can also be used.

    e.g.

    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
      switch [HTTP::host] {
        "example.in" -
        "www.example.in" {
          HTTP::redirect "http://home.example.co.in[HTTP::uri]"
        }
      }
    }
    }
    
    [root@ve10:Active] config  curl -IL http://example.in/something
    HTTP/1.0 302 Found
    Location: http://home.example.co.in/something
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    HTTP/1.1 404 Not Found
    Date: Wed, 19 Jun 2013 14:14:19 GMT
    Server: Apache/2.2.3 (CentOS)
    Connection: close
    Content-Type: text/html; charset=iso-8859-1