Project

General

Profile

Mod redirect » History » Revision 18

Revision 17 (Seldaek, 2008-03-27 01:16) → Revision 18/35 (Sfiera, 2008-11-06 18:20)

h1. [[TracNav(DocsToc)]] 

 <pre> 

 #!rst 
 =============== 
 URL Redirection 
 =============== 

 h2. -------------------- 
 Module: mod_redirect 
 -------------------- 

 .. meta:: 
   :keywords: lighttpd, redirect 
  
 .. contents:: Table of Contents 

 h2. Description 
 =========== 

 The redirect module is used to specify redirects for a set of URLs. 

 h2. Options 
 ======= 

 h3. url.redirect 

 Redirects 
   redirects a set of URLs externally 
  
 
  
   e.g. 

 <pre> 
 :: 
  
     url.redirect = ( "^/show/([0-9]+)/([0-9]+)$" => "http://www.example.org/show.php?isdn=$1&page$2", 
                  
                      "^/get/([0-9]+)/([0-9]+)$"    => "http://www.example.org/get.php?isdn=$1&page$2" ) 

 

     # make an external redirect 
 
     # from any www.host (with www.) to the host (without www.) 
 
     $HTTP["host"] =~ "^www\.(.*)$" { 
   
       url.redirect = ( "^/(.*)" => "http://%1/$1" ) 
 
     } 
 </pre> 

 h3. url.redirect-code (Added in 1.5.0) 

 Defines 
   defines the http code that is sent with the redirect URL 

 
  
   e.g. 

 <pre> 
 :: 

     url.redirect-code = 302 
 </pre> 

 h2. Example 

 Some people love the www part in the url. A general solution to move all non www. hosts to its www equivalent: :: 

 <pre> 
 

     $HTTP["host"] =~ "^([^.]+\.[^.]+)$" { 
   
       url.redirect = ( 
     
         ".*" => "http://www.%1" 
   
       ) 
 
     } 
 </pre> 

  

 Moving any subdomains except a few to www.example.org: (Note: The second match is required since a non-match doesn't set any groups) :: 

 <pre> 
 

     $HTTP["host"] !~ "^(www|mail|mysql)\.(example\.org)$" { 
   
       $HTTP["host"] =~ "^(.+\.)?(example\.org)$" { 
     
         url.redirect = ( 
       
           "^/(.*)" => "http://www.%2/$1" 
     
         ) 
   
       } 
 
     }  
  

 </pre>