Forum Discussion

ERLomboy_27803's avatar
ERLomboy_27803
Icon for Nimbostratus rankNimbostratus
Jul 11, 2014

Help reviewing an iRule

Hi,

Can someone help me out customize an existing iRule?

when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] ne "/superbook" } {
    switch -exact -- [string tolower [HTTP::host]] {
        "www.discoverypage.com" {
            if {[TCP::local_port] == 80} {
                HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
            }
             elseif { [string tolower [HTTP::uri]] starts_with "/gospels/" } {
                if { [string tolower [HTTP::host]] ne "gospels.discoverypage.com" } {
                      HTTP::respond 301 Location "https://gospels.discoverypage.com[HTTP::uri]"
                } 
              } 

        }
        "discoverypage.com" {
            if { [matchclass $::wwwredirects equals [string tolower [HTTP::path]]] } {
                HTTP::respond 301 Location "https://www.discoverypage.com[HTTP::uri]"
            } elseif { [TCP::local_port] == 80 } {
                HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
            } elseif { [string tolower [HTTP::uri]] starts_with "/dotnet/excel/114/" || [string tolower [HTTP::uri]] starts_with "/dotnet/excel/102/" } {
                HTTP::respond 301 Location "https://www.discoverypage.com[HTTP::uri]"
            }
            elseif { [string tolower [HTTP::uri]] starts_with "/forumsdotnet/" } {
                if { [string tolower [HTTP::host]] ne "forums.discoverypage.com" } {
                      HTTP::respond 301 Location "https://forums.discoverypage.com[HTTP::uri]"
                } 
            } 

        }
        default {
            if { [TCP::local_port] == 80 } {
                HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
            }

        }

    }
} else {
    HTTP::redirect http://superbook.discoverypage.com 
}

}

We have a site (superbook.discoverypage.com) that will be shutdown but the market team wants the site still get redirected to our main site (www.discoverypage.com). When I type the cname to a browser, it adds its name as a prefix to the main site.

Please help modify the iRule above so when users try to hit superbook.discoverypage.com, it will get redirected to www.discoverpage.com.

I'm not sure what to do as well with the else statement since the site superbook.discoverypage.com will eventually get shut down. Please advise on this as well.

PS: I replaced the sites with dummy ones. 🙂

Thanks!!!

2 Replies

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus
    1. Do you need to retain the path in the redirect?
    2. Which version LTM are you on? Judging by the "matchclass" statement it's not a current version.

    By the way, is "discoverypage.com" your actual domain? If so you may want to check your registration as it currently goes to a HugeDomains DNS hijack page.

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    This should work if both sites are using the same VIP. If they're not using the same VIP you'll want to move the redirect from superbook.discoverypage.com to www.discoverypage.com to its own iRule and assign that to the VIP for superbook.

    when HTTP_REQUEST {
    
        if { [HTTP::host] equals "superbook.discoverypage.com" } {
    
            HTTP::respond 301 Location "http://www.discoverypage.com/"
    
        } else {
    
            switch -exact -- [string tolower [HTTP::host]] {
                "www.discoverypage.com" {
                    if {[TCP::local_port] == 80} {
                        HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
                    }
                     elseif { [string tolower [HTTP::uri]] starts_with "/gospels/" } {
                        if { [string tolower [HTTP::host]] ne "gospels.discoverypage.com" } {
                              HTTP::respond 301 Location "https://gospels.discoverypage.com[HTTP::uri]"
                        } 
                      } 
    
                }
                "discoverypage.com" {
                    if { [matchclass $::wwwredirects equals [string tolower [HTTP::path]]] } {
                        HTTP::respond 301 Location "https://www.discoverypage.com[HTTP::uri]"
                    } elseif { [TCP::local_port] == 80 } {
                        HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
                    } elseif { [string tolower [HTTP::uri]] starts_with "/dotnet/excel/114/" || [string tolower [HTTP::uri]] starts_with "/dotnet/excel/102/" } {
                        HTTP::respond 301 Location "https://www.discoverypage.com[HTTP::uri]"
                    }
                    elseif { [string tolower [HTTP::uri]] starts_with "/forumsdotnet/" } {
                        if { [string tolower [HTTP::host]] ne "forums.discoverypage.com" } {
                              HTTP::respond 301 Location "https://forums.discoverypage.com[HTTP::uri]"
                        } 
                    } 
    
                }
                default {
                    if { [TCP::local_port] == 80 } {
                        HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
                    }
    
                }
    
        }
    
         removed redirect to superbook.discoverypage.com
    
    }