Forum Discussion
Replacing the protocol from http to https for certain domain
I am trying to replace the protocol of the Location from http to https for certain domains(url) with iRules but getting error with it.
when HTTP_RESPONSE {
if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains "http://" ) and ( class match [HTTP::header Location] contains ssl-domain-data-group) } {
HTTP::header replace [string map -nocase {"http://" "https://"} [HTTP::header Location]]
}
}
Is the syntax wrong? I am new to iRules, so any help is greatly appreciated.
7 Replies
- oguzy
Cirrostratus
Hi SK74,
class match filter should be in brackets like this.
when HTTP_RESPONSE { if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains "http://" ) and ( [ class match [HTTP::header Location] contains ssl-domain-data-group ] ) } { HTTP::header replace [string map -nocase {"http://" "https://"} [HTTP::header Location]] } }Also you can try the below one:
when HTTP_RESPONSE { if { [HTTP::header exists Location] } { set location_info [HTTP::header Location] if { ( $location_info contains "http://" ) and ( [class match $location_info contains ssl-domain-data-group ] ) } { HTTP::header replace [string map -nocase {"http://" "https://"} $location_info]] } } }- SK74_347537
Nimbostratus
Problem solved! Thanks for the help, really appreciate it. Need to add "Location" before replace to correctly modify the HTTP header.
when HTTP_RESPONSE { if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains "http://" ) and ( [ class match [HTTP::header Location] contains ssl-domain-data-group ] ) } { HTTP::header Location replace [string map -nocase {"http://" "https://"} [HTTP::header Location]] } }
- oguzy_191375
Nimbostratus
Hi SK74,
class match filter should be in brackets like this.
when HTTP_RESPONSE { if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains "http://" ) and ( [ class match [HTTP::header Location] contains ssl-domain-data-group ] ) } { HTTP::header replace [string map -nocase {"http://" "https://"} [HTTP::header Location]] } }Also you can try the below one:
when HTTP_RESPONSE { if { [HTTP::header exists Location] } { set location_info [HTTP::header Location] if { ( $location_info contains "http://" ) and ( [class match $location_info contains ssl-domain-data-group ] ) } { HTTP::header replace [string map -nocase {"http://" "https://"} $location_info]] } } }- SK74_347537
Nimbostratus
Problem solved! Thanks for the help, really appreciate it. Need to add "Location" before replace to correctly modify the HTTP header.
when HTTP_RESPONSE { if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains "http://" ) and ( [ class match [HTTP::header Location] contains ssl-domain-data-group ] ) } { HTTP::header Location replace [string map -nocase {"http://" "https://"} [HTTP::header Location]] } }
- Stanislas_Piro2
Cumulonimbus
you can use multiple value pair in string map command:
when HTTP_RESPONSE { if { [HTTP::header exists Location] } { HTTP::header replace [string map -nocase {"http://www.example.com" "https://www.example.com" "http://www2.example.com" "https://www2.example.com" "http://www3.example.com" "https://www3.example.com" "http://www4.example.com" "https://www4.example.com"} [HTTP::header Location]] } } - Adidasn2019_247
Nimbostratus
Is the 'Https' being stripped off to 'http'?
- SK74_347537
Nimbostratus
The other way around. Stripping the "http" from the location and replacing it with "https".
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
