Forum Discussion
AndyCooney_1337
May 22, 2011Nimbostratus
rewrite .com to .org for any domain
We host many of our sites as .org but still register the .com and .net domains. We'd like to have a single VIP that takes any "requested_domain.com" and rewrites it to "requested_domain.org". Currently we use a rule that I found on this site by Denny Payne:
when HTTP_REQUEST {
if { [HTTP::host] contains "mysite.com" }
{ HTTP:: redirect http://www.mysite.org }
}
This works great however every time we add another domain we have to modify the iRule. I'd like to create one that works on any request.
If it were to turn mysite.com into a string that it could strip off the .com from and then add a .org to the end redirecting to the new string it would be perfect however I'm not sure how to manipulate strings like that in the iRules world.
Thanks,
Andy
- Ed_Hammond_2611NimbostratusUse regsub or split/join to manipulate the string.
- hooleylistCirrostratusI think you could do this with string commands more efficiently:
when HTTP_REQUEST { Check if host doesn't end with .org and has at least one alpha character if { not ([string tolower [HTTP::host]] ends_with ".org") and [string match {[a-zA-Z]} [HTTP::host]] }{ Redirect to the same host with the last three characters removed and org added HTTP::redirect "http://[string range [HTTP::host] 0 end-3]org[HTTP::uri]" } }
- Michael_YatesNimbostratusYet another way to do it üôÇ
when HTTP_REQUEST { if { [string tolower [HTTP::host]] ends_with "com" } { set host [string map -nocase {com org} [HTTP::host]] HTTP::redirect "http://$host[HTTP::uri]" } }
- AndyCooney_1337NimbostratusThank you both so much for your replies.
- hooleylistCirrostratusMaybe the issue was that I left off the original URI? I edited the example above to add that.
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