8

I have a lighttpd-Setup pointing to the document-root /var/www. However, I want the URL other/ to point to /some/other/dir. This I'm doing with the following config:

$HTTP["url"] =~ "^/other($|/)" {
  server.document-root = "/some/other/dir"
}

However, if I access 'http://myhost/other', lighttpd tries to access /some/other/dir/other instead of just /some/other/dir. Is it possible to somehow strip the /other but keep any further URL segments? So for instance, http://myhost/other/sub/foo.txt should point to /some/other/dir/sub/foo.txt.

j0k
  • 21,914
  • 28
  • 75
  • 84
Remo
  • 2,160
  • 2
  • 20
  • 33

1 Answers1

11

Instead of trying to set server.document-root, you can use mod_alias to achieve this:

server.modules = ( ..., "mod_alias" )

...

alias.url = ( "/other/" => "/some/other/dir/" )

This will create an alias such that all requests to /other/ and resources inside that folder will be redirected to /some/other/dir/ on the file system, with a request directly to /other/ being pointed directly to the root of /some/other/dir/, just like you want.

Greg
  • 8,695
  • 6
  • 45
  • 89
  • I can confirm that the above works in 2021 still. I had to alias a directory with autogenerated images just now (I abandoned apache's httpd in favour of lighttpd years ago because apache became more and more complex; also the config format change annoyed me). After using the alias.url= specification I could simply map it onto "/images/" and that works; all images are displayed fine, including the display from a .cgi file (I still use them in 2021!). Don't forget the trailing / there as that one seems important. – shevy Mar 08 '21 at 19:26