Lighttpd mod_rewrite

I've migrated my teeny-weenie Xen web/mail server to Debian/etch. It hasn't even been rebooted (it would be a shame to spoil the uptime :-) ):

$ uprecords
     #               Uptime | System                                     Boot up
->   1   198 days, 06:16:44 | Linux      Thu Oct 12 10:12:51 2006
     2    99 days, 19:25:00 | Linux 2.6.12-xenU         Sun Oct  9 03:58:58 2005

It runs Lighttpd, a small and fast little webserver, popular in the Rails world. Lighttpd with PHP-fastcgi is probably faster than apache, and uses much less RAM.

With etch, I've finally been able to get mod_rewrite to work. So my Zapiro archive has nice URLs now :-)

Lighttpd has a very nice configuration style:

    # No WWW
    $HTTP["host"] =~ "^www\.((.+\.)?rivera\.za\.net)$" {
      url.redirect = ( ".*" => "http://%1$1" )
    # Add WWW:
    $HTTP["host"] =~ "^((foobar|someclient)\.co\.za)$" {
      url.redirect = ( ".*" => "http://www.%1$0" )
    # PHP Apps:
    $HTTP["host"] =~ "^(zapiro\.rivera\.za\.net)$" {
      url.redirect = ( "^/\?/(.*)" => "http://%1/$1" )
      url.rewrite-once = ( "^/(feed)$" => "/index.php?/$1",
                           "^/([0-9]+/[0-9]+/[0-9]+)$" => "/index.php?/$1" )

It's more logical than apache, but you have to watch out for rewrite->redirect->rewrite loops. So if you change to a clean URL syntax, you can't put in rewrites from index.php?/uglurl to /uglyurl because /uglyurl rewrites back to /index.php?/uglyurl, and you get a loop :-)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Does this work in an .htaccess

Does this work in an .htaccess file? I use apache and thus have a big long htaccess file full of nice little regexp strings - can this be easily translated over to lighttpd?

No, lighttpd doesn't do .htacc

No, lighttpd doesn't do .htaccess files (or anything similar).

Everything goes into the main server config file (or gets sourced/included from there)

Hi, I'm a little confused...d


I'm a little confused...does each domain have it's own config file? Surely having 1 config file with rewrite rules would confuse it. What happens if you have 2 domains with different rewrite rules?

Any help would be appreciated :)


No, it's all in one config fil

No, it's all in one config file.

You match the domain with a $HTTP["host"] = blah {}, and everything inside that stanza applies to that domain.

Obiviously you could match on other things, too...

It can have multiple files, in

It can have multiple files, in the 7.10 release of ubuntu it runs differents files for each mod .. you can do the same with hosts


So how do you switch to Clean URLs while running lighttpd?

Set up the redirect

Set up the appropriate redirects and then you'll be able to turn them on.


I love Lua, I love lighty, and that's why I recommend mod_magnet. You could probably implement your own .htaccess-ish support with it fairly easily if you wanted to.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.