Project

General

Profile

HowToRedirectHttpToHttps » History » Revision 21

Revision 20 (stbuehler, 2012-09-18 00:08) → Revision 21/33 (stbuehler, 2012-09-18 00:17)

h1. How to redirect HTTP requests to HTTPS 

 Since 1.4.19 the following should work. For older versions check the history of this page... or just update, srsly. 

 h1. Example 1 - redirect everything 

 <pre> 
 $HTTP["scheme"] == "http" { 
     # capture vhost name with regex conditiona -> %0 %1 in redirect pattern 
     # must be the most inner block to the redirect rule 
     $HTTP["host"] =~ ".*" { 
         url.redirect = (".*" => "https://%0$0") "https://%1$0") 
     } 
 } 
 </pre> 


 h2. Example 2 - specific url 

 <pre> 
 $HTTP["scheme"] == "http" { 
     $HTTP["host"] =~ ".*" { 
         url.redirect = ("^/phpmyadmin/.*" => "https://%0$0") "https://%1$0") 
     } 
 } 
 </pre> 

 h2. Example 3 - only for specific vhost and url 

 <pre> 
 $HTTP["scheme"] == "http" { 
     $HTTP["host"] == "sth.example.com" { 
             url.redirect = ("^/phpmyadmin/.*" => "https://sth.example.com$0") 
     } 
 } 
 </pre> 

 h2. Further stuff 

 Also works the other way round (https -> http) with @if $HTTP["scheme"] == "https"@