Search code examples
linuxurl-rewritinglighttpd

lighttpd conditional rewrite


Initially i wanted to add trailing / in my url (lighttpd)

which is possible to do with

    url.redirect = ( "^(.*[^/])$" => "$1/" ) 

Now i need to exclude some extensions like .txt, png etc. I want to add trailing slash for everything except those extensions, i dont seem to get that working.

In apache I could have used conditional rewrite, how would you do that in lighttpd.

Any directions would be highly appreciated.

Thank you


Solution

  • Just to make it together this would work (tested)

           $HTTP["url"] !~ "^(.*)(\..{3}|/)$" {
              url.redirect = (
    
               "^(.*[^/])$" => "$1/"
              )
            }
    

    @david This would create never ending loop.....

     "^(.*)\.(png|txt)$" => "$1.$2",
        "^(.*[^/])$" => "$1/"
    

    This will create ever lasting loop

    @Matthew This wont quite work as you are pushing everything to %1

    $HTTP["url"] !~ "^(.*)(\..{3}|/)$" {
      url.redirect = (
        ".*" => "%1/" 
      )
    }