Forum Discussion
Kate_Kattar_107
Nimbostratus
Jul 22, 2008URL 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
4 Replies
- The_Bhattman
Nimbostratus
Hi Kate,
There are number of ways to do this. One that comes to mind is the switch command
I.Ewhen 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 - Kate_Kattar_107
Nimbostratus
Thank You. Works perfectly and its so simple.
Much appreciated. - Kate_Kattar_107
Nimbostratus
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 " }
}
} - Andy_Herrman_22
Nimbostratus
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 " } } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects