Forum Discussion
OCC_Ops_68605
Nimbostratus
Dec 05, 2013HTTPS to HTTPS redirect
I need to redirect several https domains to one https main domain, the irule for http to https is working very good, but the same irule with https to https it does not working. Any ideas??
IheartF5_45022
Nacreous
Dec 09, 2013- Try putting * after each switch arm clause - just in case you have say :443 appended to the end
- Add 'return' after HTTP::respond (best practise inncase you have other iRule statements after the switch)
- Add logging statements in
Updated iRule;-
when HTTP_REQUEST {
log local0. "[HTTP::host] on port [TCP::local_port]"
switch -glob [string tolower [HTTP::host]] {
"domain1.com*" -
"domain2.com*" -
"www.domain1.com*" -
"www.domain2.com*" {
log local0. "redirecting"
HTTP::respond 301 Location "https://www.mymainsite.com"
return
}
}
}
- OCC_Ops_68605Dec 10, 2013
Nimbostratus
Thanks for your help, with this changes the iRule is working now. - IheartF5_45022Dec 10, 2013
Nacreous
Make suer you take the logging statements out before you go into prod!! - OCC_Ops_68605Jan 13, 2014
Nimbostratus
Hi, Do you know How Can I get the params before redirect?? Example: https://www.domain1.com/search_engine/search1 to https://www.mainsite.com/search_engine/search1 - ArieJan 13, 2014
Altostratus
I would recommend not using the * at the end, or even the -glob. You're looking for an exact match of the host, so -glob is just going to make the statement unnecessarily heavy. If a user adds :443 (or :80, or any other port) to their request this will merely impact the port; it does not change the host (or the value of [HTTP::host]. - IheartF5_45022Jan 13, 2014
Nacreous
That's not necessarily correct - most browsers will remove :80 or :443 if you enter it in the address bar, but they will not remove other ports (which is irrelevant for this discussion), and some browsers will retain :80 :443, also some robots add the port number to the Host header - it's perfectly valid and allowed by RFC. If you are really hate -glob, you could remove it and base the switch on the FQDN component of the Host header ie. switch [string tolower [getfield [HTTP::host] : 1]] { The possibility of a port number in a Host header should be catered for some way.
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