LineRate HTTP to HTTPS redirect

Here's a quick LineRate proxy code snippet to convert an HTTP request to a HTTPS request using the embedded Node.js engine. The relevant parts of the LineRate proxy config are below, as well.

By modifying the

variable, you can redirect HTTP to HTTPS as well as doing a non-www to a www redirect. For example, you can redirect a request for
. The original URI is simply appended to the redirected request, so a request for
will be redirected to

This example uses the self-signed SSL certificate that is included in the LineRate distribution. This is fine for testing, but make sure to create a new SSL profile with your site certificate and key when going to production.

As always, the scripting docs can be found here.


Put this script in the default scripts directory -

and update the
variables for your environment.

"use strict";

var vsm = require('lrs/virtualServerModule');

// domain name to which to redirect
var redirect_domain = '';

// type of redirect.  301 = temporary, 302 = permanent
var redirect_type = 302;

vsm.on('exist', '', function(vs) {
  console.log('Redirect script installed on Virtual Server: ' +;

  vs.on('request', function(servReq, servResp, cliReq) {

    servResp.writeHead(redirect_type, {
        'Location': 'https://' + redirect_domain + servReq.url



LineRate config:

real-server rs1
 ip address 80
 admin-status online
 ip address 80
 admin-status online
virtual-ip vip_example.com_https
 ip address 443
 attach ssl profile self-signed
 admin-status online
 attach virtual-ip default
 attach real-server rs1
virtual-server vs_example.com_https
 attach virtual-ip vip_example.com_https default
 attach real-server rs1
script redirect
 source file "proxy/redirect.js"
 admin-status online 


user@m1:~/ > curl -L -k -D -
HTTP/1.1 302 Found
Date: Wed, 03-Sep-2014 16:39:53 GMT
Transfer-Encoding: chunked

HTTP/1.1 200 OK
Content-Type: text/plain
Date: Wed, 03-Sep-2014 16:39:53 GMT
Transfer-Encoding: chunked

hello world

Updated Jun 06, 2023
Version 2.0

Was this article helpful?

No CommentsBe the first to comment