UTF-8 with lighttpd


Broken Arrows

The arrows in the ← Older and Newer → boxes at the page bottom looked fine on my local test web server, but appeared busted on the production server.

At the time of writing lighttpd was the server for this website. In the default setup HTML documents are served with the HTTP header

Content-Type: text/html

Your web browser would probably use iso-8859-1 for displaying in that case.

Like most websites these days this blog uses UTF-8.

lighttpd's default encoding settings are defined in the global config under

mimetype.assign = (
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",

My first try to override the setting for HTML documents for the www.augensalat.de virtual host with

mimetype.assign = ( ".html" =>  "text/html" )

replaced the whole global mimetype.assign list with this single definition.

OK, since I'm the server administrator I could simply change the global default, but this would affect all websites served by this lighttpd webserver.

A more defensive solution is to constrain the rewritten mimetype.assign for www.augensalat.de to URLs that end either with a slash / or with .html:

$HTTP["url"] =~ "(\.html|\/)$" {
    mimetype.assign = ("" => "text/html; charset=utf-8")