Forum Discussion

eirikn's avatar
eirikn
Icon for Nimbostratus rankNimbostratus
Oct 15, 2015

Redirection array iRule does not hit

Hi,

Our customer is moving four separate sites to the existing web environment and are in need of redirections of several URL's.

Let's call the sites:

www.alfasite.com www.alfasite.se www.betasite.com www.betasite.se

At every site most of the url's must redirect to the new space on the existing page like this:

www.alfasite.com should redirect to www.existingsite.com/alfa/alfasite/ www.betasite.com should redirect to www.existingsite.com/beta/betasite/

It get's difficult when several of the url's need to be redirected to specific url's on the existing site like this:

www.alfasite.com/contactus should redirect to www.existingsite.com/alfa/alfasite/contact www.alfasite.com/spaa should redirect to www.existingsite.com/alfa/alfasite/bad-rom www.alfasite.com/cykelteori.aspx should redirect to www.existingsite.com/alfa/alfasite/bikes +++ about 200 more of these for both sites, .com and .se.

I've made iRule with a array that usualy handles these kind of redirects in a simple matter, but whith these sites we also need a "catch all" to redirect all url's that are not specified in the array (as most of them should redirect to the main space on the existing site)

I have made 2x iRules, one for each site. Each irule redirects both .com and .se.

I have also made a "catch all" irule that i have placed as lowest priority, that will catch all url's not redirected by the array irules. Notice i have a "event disable" in the redirection arrays to make sure it does not hit the "catch all" irule if the condition is met.

Irules as follows:

2x of this, i will only paste 1. The other one is exactly the same, just different domains and url's:

http://pastebin.com/XD4x6viA

And the catch all irule:

when HTTP_REQUEST {

if { [HTTP::host] contains "alfasite.se" } {

HTTP::respond 301 location "https://www.existingsite.se/alfa/alfasite/" }

if { [HTTP::host] contains "alfasite.com" } {

HTTP::respond 301 location "https://www.existingsite.com/alfa/alfasite/" }

if { [HTTP::host] contains "betasite.se" } {

HTTP::respond 301 location "https://www.existingsite.com/beta/betasite/" }

if { [HTTP::host] contains "betasite.com" } {

HTTP::respond 301 location "" }

}

In my staging environment i can only get on of the array irules to work. Some times its alfasite, sometimes it's betasite. The iRule order does not seem to matter. When it does not work, it look's like it does not hit the repsective array irule, but only the catchall.

Any ideas?

4 Replies

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    My first question is whether redirecting to the subfolders is necessary. It'll kill SEO and is confusing from a usability point of view.

     

    Is reflecting the subfolders a requirement or is it deemed a consequence of the migration?

     

    I've dealt with a number of migrations where it was assumed that subfolders would be required and the customer acquiesced to using them. However, it's usually not necessary to change the URLs.

     

  • Hi,

    your irule is so long...

    it seems your have only a few redirect URLs, you can use a switch command instead of a array...

    when HTTP_REQUEST {
    
        Check the requested HTTP path
       switch [string tolower [HTTP::host]] {
            "www.alfasite.se" {
                switch [string tolower [HTTP::path]] {
                     "/1011-inspiration-sign.aspx" -
                     "/11/10-spectacular-hair-show-at-selma-cityspa.aspx" -
                     "/11/12-dance,-dance,-dance!.aspx" {HTTP::respond 301 Location "https://www.existingsite.se/alfa/alfasite/featured-amenities/living-room/"; return}
                     "/105-girls-night-at-selma-cityspa.aspx" {HTTP::respond 301 Location "https://www.existingsite.se/alfa/alfasite/featured-amenities/living-room/"; return}
                     default {}
                 }
            }
            "www.alfasite.com" {
                switch [string tolower [HTTP::path]] {
                     "/meeting.aspx" -
                     "/pictures-conference.aspx" {HTTP::respond 301 Location "https://www.existingsite.com/alfa/alfasite/conference-in-stockholm/"; return}
                     "/enlivingroom.aspx" -
                     "/livingroom_juli.aspx" -
                     "/13/11-living-room---traning.aspx" -
                     "/284-livingroom-by-juiceboy--swingkid.aspx" {HTTP::respond 301 Location "https://www.existingsite.com/alfa/alfasite/featured-amenities/living-room/"; return}
                     default {}
                 }
            }
    }
    

    The minus character at the end of line is to do the same command for multiple statements.

    the return command is to quit the irule

  • Hi,

    the provided irule is a example, I did not describe all URLs of you irule.

    for the default behavior if the URI does not match one of known URL, change the default statement to:

    default { HTTP::respond 301 Location "https://www.existingsite.com/alfa/alfasite/"; return}
    

    the

    return
    is to leave the irule. you can add a
    event disable
    before the
    return
    command to be sure other irule won't be executed.

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    To add handling for the main domain:

    switch [string tolower [HTTP::host]] {
            "www.alfasite.se" - 
            "alfasite.se {
            ...