Forum Discussion
iRule to switch hostnames to www.
Hi all, this is my first post and I'm not an F5 legend so please bare with me if this is obvious.
Our customer facing websites are published with a full www URL - i.e. www.mycompany.com. This DNS record is a CNAME which points to an A record of live.mydomain.com.
[The idea is that if the web servers behind that VS need to be taken down, we can very quickly change that CNAME to instead point to backup.mydomain.com in another cluster (but behind the same LB). CNAME changes propagate a lot quicker than A record changes so this is effectively a manual GTM.]
Anyway, our problem is that because live.mydomain.com and backup.mydomain.com are public facing, people who know these hostnames can access the site effectively on the wrong URL - this is bad for our internet stats as sites like google can see our content on 2-3 urls and therefore mark us down in search.
I've created an iRule to 301-redirect either live. or backup. to www.mydomain.com but would like to ask if this logic is correct, or indeed whether it could be more efficient for my needs, the last thing I want is to get stuck in a loop!:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"live.mydomain.com" {
HTTP::respond 301 Location "http://www.mydomain.com[HTTP::uri]"
}
"backup.mydomiain.com" {
HTTP::respond 301 Location "http://www.mydomain.com[HTTP::uri]"
}
}
}
Here's hoping.
Cheers, Steve.
- Michael_YatesNimbostratusIf both of your URL's are mapped to Virtual Servers on the same BigIP then each should point to a different pool of servers behind the same device.
- Steve_87971NimbostratusHi Michael, thank you for responding to me.
- Michael_YatesNimbostratusI think I understand.
- hoolioCirrostratusThe rule I've written does seem to do this - I've applied it to both the live and backup VS and tested - but I'm wondering whether it could be simplified with an OR statement...
- Steve_87971NimbostratusMichael, thank you for that suggestion - it hadn't occurred to me to look at it as a robot problem so I'll put some investigation into that. Wood for the tree's and all that...
Recent Discussions
Related Content
* 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