Forum Discussion

Kate_Kattar_107's avatar
Kate_Kattar_107
Icon for Nimbostratus rankNimbostratus
Jul 22, 2008

URL forwarding help

I have a fairly simple request but need some guidance regarding the best way to do it. My client is lauching a new website and would like to forwarding 30 other urls to this new url. For instance:

 

www.site1.com should be forwarded to www.newsite.com/site1

 

www.site2.com should be forwarded to www.newsite.com/site2

 

 

Should I be using irules to do this?

 

 

What syntax should I use? Something like this:

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals {www.prioryhospital.com} and [HTTP::uri] equals "/"} {HTTP::redirect "http://bbc.co.uk"

 

}

 

return

 

}

 

 

This incidently doesn't work and I imagine its a little messy.

 

 

Cheers

 

Kate
  • Hi Kate,

    There are number of ways to do this. One that comes to mind is the switch command

    I.E

     
     when HTTP_REQUEST { 
        switch -glob [HTTP::host] { 
        "www.site1.com" { HTTP::redirect "http://www.newsite.com/site1" } 
        "www.site2.com" { HTTP::redirect "http://www.newsite.com/site2" } 
        "www.site3.com" { HTTP::redirect "http://www.newsite.com/site3" } 
        "www.siteN.com" { HTTP::redirect "http://www.newsite.com/siteN" } 
        . 
        . 
        . 
        } 
     } 
     

    Click here to find out more about the switch command

    Hope this helps

    CB

  • I have now been asked to make further additions to the rule. The following does not work. Do I need to use a different value other than [HTTP::host]?

     

     

    when HTTP_REQUEST {

     

    switch -glob [HTTP::host] {

     

     

    "host.co.uk/about.cfm" { HTTP::redirect "http://www.newhost.co.uk/page1 " }

     

    "host.co.uk/audit.cfm" { HTTP::redirect "http://www.newhost.co.uk/aboutpage " }

     

     

    }

     

    }
  • HTTP::host only gives you the hostname (host.co.uk). HTTP::uri will give you the path (/about.cfm), so try:

     
     when HTTP_REQUEST { 
       switch -glob "[HTTP::host][HTTP::uri]" { 
         "host.co.uk/about.cfm" { HTTP::redirect "http://www.newhost.co.uk/page1 " } 
         "host.co.uk/audit.cfm" { HTTP::redirect "http://www.newhost.co.uk/aboutpage " } 
       } 
     } 
     

    You might run into case issues though (if someone goes to host.co.uk/About.cfm it wouldn't be caught). In which case you'd want to do something like this:

     
     when HTTP_REQUEST { 
       switch -glob [string tolower "[HTTP::host][HTTP::uri]"] { 
         "host.co.uk/about.cfm" { HTTP::redirect "http://www.newhost.co.uk/page1 " } 
         "host.co.uk/audit.cfm" { HTTP::redirect "http://www.newhost.co.uk/aboutpage " } 
       } 
     }