Forum Discussion

pkhatri_72515's avatar
pkhatri_72515
Icon for Nimbostratus rankNimbostratus
Jan 15, 2010

need 301 redirect help please.

301 redirect of following. Can you please help me out on a best way to do this in F5? iRule? version 9.3.

 

 

http://www.bla.com/home/index.cfm?&LANG=EN&CountryLanguage=EN_GL -------> http://www.bla.com/gl

 

http://www.bla.com/home/index.cfm?&LANG=EN&CountryLanguage=EN_AP-------> http://www.bla.com/ap

 

http://www.bla.com/home/index.cfm?&LANG=FR&CountryLanguage=FR-------> http://www.bla.com/fr

 

http://www.bla.com/home/index.cfm?&LANG=DE&CountryLanguage=DE-------> http://www.bla.com/de

 

http://www.bla.com/home/index.cfm?&LANG=EN&CountryLanguage=EN_IR-------> http://www.bla.com/ie

 

http://www.bla.com/home/index.cfm?&LANG=IT&CountryLanguage=IT-------> http://www.bla.com/it

 

http://www.bla.com/home/index.cfm?&LANG=NL&CountryLanguage=NL-------> http://www.bla.com/nl

 

http://www.bla.com/home/index.cfm?&LANG=PR&CountryLanguage=PR-------> http://www.bla.com/pr

 

http://www.bla.com/home/index.cfm?&LANG=SP&CountryLanguage=SP-------> http://www.bla.com/es

 

http://www.bla.com/home/index.cfm?&LANG=SW&CountryLanguage=SW-------> http://www.bla.com/se

 

http://www.bla.com/home/index.cfm?&LANG=EN&CountryLanguage=EN_UK-------> http://www.bla.com/uk

 

 

 

Thanks,

 

7 Replies

  • I am not certain how elegant this is and I haven't had a chance to test it out, but this should get you going in the right direction:

       
       when HTTP_REQUEST {   
       switch -glob [string tolower [HTTP::uri] ] {   
       "*countrylanguage=en_gl*" {    
       HTTP::respond 301 Location http://www.bla.com/gl   
       }   
       "*countrylanguage=en_ap*" {   
       HTTP::respond 301 Location http://www.bla.com/ap    
       }   
       "*countrylanguage=fr*" {   
       HTTP::respond 301 Location http://www.bla.com/fr   
       }   
       "*countrylanguage=de*" {   
       HTTP::respond 301 Location http://www.bla.com/de   
       }   
       "*countrylanguage=en_ir*" {   
       HTTP::respond 301 Location http://www.bla.com/ie   
       }   
       "*countrylanguage=it*" {   
       HTTP::respond 301 Location http://www.bla.com/it   
       }   
       "*countrylanguage=nl*" {   
       HTTP::respond 301 Location http://www.bla.com/nl   
       }   
       "*countrylanguage=pr*" {   
       HTTP::respond 301 Location http://www.bla.com/pr   
       }   
       "*countrylanguage=sp*" {   
       HTTP::respond 301 Location http://www.bla.com/es   
       }   
       "*countrylanguage=sw*" {   
       HTTP::respond 301 Location http://www.bla.com/se   
       }   
       "*countrylanguage=en_uk*" {   
       HTTP::respond 301 Location http://www.bla.com/uk   
       }   
       }   
       }   
  • Here is a another way to do this. It hasn't been tested but it's a bit more refined.

         
      when HTTP_REQUEST {  
       switch -glob [string tolower [uri::query [HTTP::uri] CountryLanguage]] {  
         "en_gl" {      
         HTTP::respond 301 Location "[HTTP::host]/gl"     
         }     
         "en_ap" {     
         HTTP::respond 301 Location "[HTTP::host]/ap"      
         }     
         "fr" {     
         HTTP::respond 301 Location "[HTTP::host]/fr"     
         }     
         "de" {     
         HTTP::respond 301 Location "[HTTP::host]/de"     
         }     
         "en_ir" {     
         HTTP::respond 301 Location "[HTTP::host]/ie"     
         }     
         "it" {     
         HTTP::respond 301 Location "[HTTP::host]/it"     
         }     
         "nl" {     
         HTTP::respond 301 Location "[HTTP::host]/nl"     
         }     
         "pr" {     
         HTTP::respond 301 Location "[HTTP::host]/pr"     
         }     
         "sp" {     
         HTTP::respond 301 Location "[HTTP::host]/es"     
         }     
         "sw" {     
         HTTP::respond 301 Location "[HTTP::host]/se"     
         }     
         "en_uk" {     
         HTTP::respond 301 Location "[HTTP::host]/uk"     
         }  
         Default {  
            HTTP::respond 301 Location "[HTTP::host]/nosite.html"   
         }  
        }     
      }  
      

    I hope this helps

    Bhattman
  • Nice ones...

     

     

    Just make sure to include the protocol in the redirect:

     

     

    HTTP::respond 301 Location "http://[HTTP::host]/gl"

     

     

    Aaron
  • Related question. Can someone help combine a redirect rule that looks for both the host and uri (everything after the /)?

     

     

    Our existing rule which uses HTTP::host works just fine:

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::host]] {

     

    "*sample*" {HTTP::redirect "http://site.sample.com/default.aspx"}

     

    "*test*" {HTTP::redirect "https://site.test.com/Pages/home.aspx"}

     

    default {HTTP::redirect "https://www.test.com"}

     

    }

     

    }

     

     

    Problem now is that I'm being asked to redirect *sample.com/folder1 to -> http://site.sample.com/folder1. I tried adding an IF before the switch statement (using HTTP::path and HTTP::uri) with minimal success. How would you go about doing this?

     

     

    Thanks in advance for the support.

     

     

     

  • Hi Brandon,

    Here is one option which combines the host and path for the string to check in the switch statement:

     
     when HTTP_REQUEST { 
      
        switch -glob "[string tolower [HTTP::host]][HTTP::path]" { 
           "*sample.com/folder1*" {HTTP::redirect "http://site.sample.com/default.aspx"} 
           "*test.com/*" {HTTP::redirect "https://site.test.com/Pages/home.aspx"} 
           default {HTTP::redirect "https://www.test.com"} 
        } 
     } 
     

    Note, that I've tried to make the *test* case more specific to reduce the chance that the string "test" will be found in just the path. If that doesn't work for you, can you provide more examples of what you do/don't want to match for each case?

    Aaron