Forum Discussion
(Urgent) iRule for Http to Https on non-standard port
I have a web site that only takes requests on port 99 (I have no control over this). In the web page the developers have hardcoded http links (once again no control :( ). I also have a APM application to the Virtual Server. I need an iRule to redirect the the requests from http to https. I'm struggling because http and https are going to the same port so I can create another VS and do _sys_https_redirect iRule.
I also tried the following iRule but it getting a Secure Connection Failed/Client closed. I guess the trick is to redirect before the VS fully parses the response and gets an error.
First iRule when HTTP_REQUEST { if { [SSL::mode] == 0 } { HTTP::redirect https://[HTTP::host]:99[HTTP::uri] } }
Second Attempt when HTTP_REQUEST_SEND { if { [SSL::mode] == 0 } { HTTP::redirect https://[HTTP::host]:99[HTTP::uri] } }
6 Replies
- Kevin_Stewart
Employee
So just to clarify, is that HTTP and HTTPS on the same IP and port? If the application only supports port 99, does it matter that the VIPs can be 80 and 443?
I've tried making the pool & node use service port 99 while using 80 & 443 in two VS's. The application is IIS and it's using host header so it expects an FQDN with someapp.corp.com:99 . Unless I'm missing something.
- Kevin_Stewart
Employee
Well, it's pretty straight forward to replace the Host header.
when HTTP_REQUEST { HTTP::header replace Host "someapp.corp.com:99" }Given that and the fact the pool members are physically listening on port 99, the application shouldn't have any idea that there's a proxy in front doing 443 or 80.
- Stanislas_Piro2
Cumulonimbus
Hi,
Did you try to configure a rewrite profile to rewrite response page:
- Kevin_Stewart
Employee
You can use a rewrite profile or a STREAM iRule, but ultimately you have to catch these bad URLs in server responses and rewrite them to match the external FQDN.
when HTTP_REQUEST { HTTP::header remove Accept-Encoding STREAM::disable } when HTTP_RESPONSE { if { ( [HTTP::header exists Location] ) and ( [HTTP::header Location] contains ":99" ) } { HTTP::header replace Location "https://someapp.corp.com/" } if { [HTTP::header Content-Type] contains "text" } { STREAM::expression {@http://someapp.corp.com:99@https://someapp.corp.com@} STREAM::enable } } - TejasTh_307036
Nimbostratus
I have the same requirement, if user access the URL with HTTPS, no change in URL. If user access the URLwith HTTP, should redirect to https, I am also using non-standard port URLS.
https://abc.com:8888 ==> no change
http://abc.com:8888 ==> redicet to https://abc.com:8888
It's perfectly working fine with below config
1) Create SSL Client profile with allowing Non-SSL Connections ( You need to modify default config)
2) Create VIP with 8888 port and use SSL client profile
3) Configure below iRule
when HTTP_REQUEST {
if { [URI::protocol [HTTP::uri]] eq "http" } {
HTTP::redirect https://[getfield [HTTP::host] ":" 1]:[TCP::local_port][HTTP::uri]
}}
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