cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect http and https with on rule ?

SOLVED
crackerjack
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. "example.com" to the same but with path -> "example.com/test"

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" ) == "example.com" {

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

      http.redirect( "http://example.com/test/" );

    }

Now when somebody called the url example.com with https -> https://example.com

this must be redirect to example.com/test too but with https.

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

$HostHeader = http.getHostHeader();

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

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

   if (ssl.isSSL())

      http.redirect( "https://example.com/test/" );

else

http.redirect( "http://example.com/test/" );

    }

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

Could somebdy help here or have a hint for me?

Thanks.

Regards,

Michael

1 ACCEPTED SOLUTION

Accepted Solutions
dnahas
Contributor

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" ) == "www.example.com" ){


        http.setpath( "/test/" );


}


View solution in original post

1 REPLY 1
dnahas
Contributor

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" ) == "www.example.com" ){


        http.setpath( "/test/" );


}