Forum Discussion
Darren_Person_2
Nimbostratus
Nov 03, 2006iRule URL Rewrite for Multiple domains
Can someone explain how to approach this problem?
I have multiple domains that each need to 302 redirect back to their primary's:
For example,
i have:
www.test.com
test.com
www.xyz.com
xyz.com
www.primary.com
(...)
all need to 302 redirect to
primary.com
Then time this by 16 different sites.
how would you approach this problem?
- You could use a class along with the matchclass command (look in the wiki for an example on that one). Or you could use a switch statement if you want all the domains within your iRule and not externalized in a class
when HTTP_REQUEST { switch [HTTP::host] { "www.test.com" - "test.com" - "www.xyz.com" - "xyz.com" - { HTTP::redirect "http://primary.com[HTTP::uri]" } } }
- Darren_Person_2
Nimbostratus
Hi Joe, - There was a good contribution to the wiki a while back outlining general guidelines on how to write fast iRules
class domain_check { "www.test.com primary.com" "test.com primary.com" "www.xyz.com secondary.com" "xyz.com secondary.com" } --- Begin iRule --- when HTTP_REQUEST { set redir [findclass [HTTP::host] $::domain_check " "] if { $redir ne "" } { HTTP::redirect "http://$redir[HTTP::uri]" } }
- Darren_Person_2
Nimbostratus
Just as a follow up on this, for those users who are currently using the "redirect" for URLS, this is considered a bad practice for SEO. - John_Pope_42012
Nimbostratus
when HTTP_REQUEST { if { [HTTP::uri] contains "select" } { use pool web_pool_web02 } elseif { [HTTP::uri] contains "survey" } { use pool web_pool_web02 } elseif { [HTTP::uri] contains "bcaonline" } { use pool web_pool_web01 } elseif { [HTTP::uri] contains "onlinene" } { use pool web_pool_web02 } elseif { [HTTP::uri] contains "onlinesubscadmin" } { use pool web_pool_web02 } elseif { [HTTP::uri] contains "MAILFORM" } { use pool cms_saiglobal } elseif { [HTTP::host] contains "saiglobal.com.au" } { HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } elseif { ([HTTP::host] contains "sai-global.com.au") and ([HTTP::uri] contains "shop") } { HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } elseif { [HTTP::host] contains "saiglobalinc.com" } { [HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } elseif { [HTTP::host] contains "qas.com.au" } { HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } elseif { ([HTTP::host] contains "www.standards.com.au") and ([HTTP::uri] contains "catalogue") } { HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } elseif { ([HTTP::host] contains "cqc-sai.com") and ([HTTP::uri] contains "shop") } { HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } elseif { ([HTTP::host] contains "sai-global.com") and ([HTTP::uri] contains "shop") } { HTTP::redirect "http://www.saiglobal.com/[HTTP::uri]" } else { use pool web_pool_shop } }
- I've corrected your iRule in your previous post (there were some formatting issues that caused the post to not display so I had to correct those anyway.
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