Showing results for 
Search instead for 
Did you mean: 

Redirect http and https with on rule ?

Occasional Contributor

Redirect http and https with on rule ?

Hi @ all,

once again I´ve a question about TS ... can´t help myself, but TS is a world of it´s own ;-)

I try to do the following - quiet simple:

I´ve to redirect an url without path eg. "" to the same but with path -> ""

for https and https, with one TS-Rule, if possible ...

This is my TS-Rule for http and it works:

$HostHeader = http.getHostHeader();

   if ( http.getheader( "host" ) == "" {

   if ( http.getPath() == "/" )  

      http.redirect( "" );


Now when somebody called the url with https ->

this must be redirect to too but with https.

My first thought was to extend the rule with syntax "if (ssl.isSSL())" ...

$HostHeader = http.getHostHeader();

   if( http.getheader( "host" ) == "" {

   if ( http.getPath() == "/"

   if (ssl.isSSL())

      http.redirect( "" );


http.redirect( "" );


but this doesn´t work, I don´t know why.

Could somebdy help here or have a hint for me?





Re: Redirect http and https with on rule ?

If the virtual server is HTTPS and you are have not enabled SSL decryption the host header is encrypted for the HTTPS, that could have been your issue.

An issue with your rule would have is all requests to / (HTTP or HTTPS) would be redirected to HTTP. To keep rule structure with your original, you would need one rule for each virtual server with a different location for each protocol.

It sounds like you want to make the redirect decision from the URL and not the Host Header. I would suggest a change in the approach to keep things simple, and users on the current "site".

Try the following (As a request rule for a HTTP virtual server or a decrypted HTTPS virtual server):

$path = http.getpath();

if( $path == "/" ){

        http.redirect( "/test/" );


If you happen to have multiple host headers in use on a single virtual server and need to use the header to determine if action should take place, try this:

$path = http.getpath();

if( $path == "/"

        || http.getheader( "Host" ) == "" ){

        http.setpath( "/test/" );