Forum Discussion
URL Redirect Switch not detecting on host for base domain
I am wanting to redirect certain hosts to HTTPS for offload. my iRule is working for hosts within the domain (e.g. ) but not for base domain host (e.g. domain.com).
The below iRule is working for www and uat, but not the base domain. Any assistance for what is wrong.
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "domain.com" { HTTP::respond 301 Location "https://domain.com[HTTP::uri]"} "; { HTTP::respond 301 Location "https://www.domain.com[HTTP::uri]"} "uat.domain.com" { HTTP::respond 301 Location "https://uat.domain.com[HTTP::uri]"} default {pool default_pool} } }
- DennisJann
Nimbostratus
I had to remove the ";" after ";, but otherwise your iRule syntax works as expected for me.
You could try using
to test against the IP address of your VIP to see if you get the desired behavior.curl
curl -iv -H "Host: domain.com" http:///
If it works, compare against the output of:
curl -iv http://domain.com/
While your iRule syntax isn't wrong, it could be re-written as:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "domain.com" - "www.domain.com" - "uat.domain.com" { HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]" } default { pool default_pool } } }
- Andy_McGrath
Cumulonimbus
Expanding on from DannisJann’s answer, I recommend using
around thegetfield
command to remove any trailing port e.g.HTTP::host
should still match in the switch statement.curl -iv http://domain.com:80/
Also you do not need to use the
command as you have not overwritten the Virtual Server configured pool earlier in the iRule.pool
If you have used the
command in an earlier iRule then you may want to put your pool selection back in but recommend usingpool
instead of the pool by name.pool [LB::server pool]
when HTTP_REQUEST { switch [string tolower [getfield [HTTP::host] : 1]] { "domain.com" - "www.domain.com" - "uat.domain.com" { HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]" } default { return } } }
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