Forum Discussion
Prepend www, redirect to https, and preserve full URL
Hello All,
I would like to use an iRule that does the following type of redirect/rewrite:
http://testsite.com/about -> https://www.testsite.com/about
Ideally, if other valid urls like the below are entered, I do not want it to prepend the www:
http://blog.testsite.com -> https://blog.testsite.com
Searching around, I've found iRules that do most of what I want, but not the whole thing.
Regards,
Jason
2 Replies
- Mark_22062
Nimbostratus
Hi Jason,
Give this a try.
when HTTP_REQUEST { if { [string to lower [HTTP::host]] eq "testsite.com" } { HTTP::redirect https://www.[getfield [HTTP::host] ":" 1][HTTP::uri] } else {HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]} } - VernonWells
Employee
If you are running at least 11.4, you can also achieve this using a Local Traffic Policy
It might look like this:
ltm policy www-redirect-append { controls { forwarding } requires { http } rules { rule-testsite.com { actions { 0 { http-reply redirect location "https://www.[getfield [HTTP::host] : 1][HTTP::uri]" } } conditions { 0 { http-host values { testsite.com } } } ordinal 1 } rule-default { actions { 0 { http-reply redirect location "https://[getfield [HTTP::host] : 1][HTTP::uri]" } } ordinal 2 } } strategy first-match }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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