Forum Discussion
AndyCooney_1337
Nimbostratus
May 22, 2011rewrite .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
5 Replies
- Ed_Hammond_2611
Nimbostratus
Use regsub or split/join to manipulate the string.
set newDomain [regsub -nocase -- {(com|net)\.*$} [HTTP::host] {org}]
HTTP::redirect "$newDomain[HTTP::uri]"
Or something to that effect ;-) - hoolio
Cirrostratus
I 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]" } }
Aaron - Michael_Yates
Nimbostratus
Yet 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_1337
Nimbostratus
Thank you both so much for your replies.
The solution provided by hoolio seemed to not work correctly, perhaps it directed the user in circles because of our setup.
The solution from Michael worked just perfectly. I modified it to actually do the same for both .com and .net redirecting to the https .org equivalent.
Thanks,
Andy - hoolio
Cirrostratus
Maybe the issue was that I left off the original URI? I edited the example above to add that.
Aaron
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
