Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use lessn, a url shortener by Shaun Inman, on my lighttpd server and he uses a .htaccess file for the redirect. I am not very good with Mod_Rewrite isn the first place otherwise some simple googling would have sufficed to convert this for lighttpd. As it is, I do not know what the 2nd and 3rd lines of the Mod_Rewrite are doing, so I cannot convert. I'd appreciate anyone's advice on those so I can have it working as it should. Thank you!

<IfModule mod_rewrite.c>
    RewriteEngine   on
    RewriteCond     %{REQUEST_FILENAME}     !-d
    RewriteCond     %{REQUEST_FILENAME}     !-f
    RewriteRule     (.*) index.php?token=$1 [QSA,L]
share|improve this question
Haha, I am and will be still be trying to figure this out in the meantime, and I just realized that I don't really understand the 4th line either (at least the (.*) and [QSA,L] parts). – Jonathan Kratzke Jun 26 '11 at 20:59
ok, this page - is helpful, but it seems like the rewrite rule has to be handled by a cgi script? – Jonathan Kratzke Jun 26 '11 at 21:07
The (.*) is a regular expression (regex) to match everything and the QSA stands for "query string append" which is anything after the ? in a URL, the L indicates this is the last line of the rewrite rule that should run if there is a match to the regex. – baraboom Jun 26 '11 at 21:09
up vote 2 down vote accepted

These two lines instruct Apache's mod_rewrite to NOT apply the rewrite rule to files (f) and directories (d) that physically exist on the file system:

RewriteCond     %{REQUEST_FILENAME}     !-d
RewriteCond     %{REQUEST_FILENAME}     !-f

For a long time, lighttpd did not support this behavior out of the box and you had to use mod_magnet with a lua script, like this example:

However, it looks like there is support now:

So, just use that rewrite construct in your lighttpd.conf, something like:

url.rewrite-if-not-file = (
  "^/(.*)$" => "/index.php?q=$1"

Hope this helps and good luck!

share|improve this answer
Thank you, that was exactly what I needed! In case anyone is searching this later for lessn, the above code should be url.rewrite-if-not-file = ( "^/(.*)$" => "/index.php?token=$1" ) – Jonathan Kratzke Jun 26 '11 at 21:16
Also, the working directory for lessn ( ) needs to have the default page (index.php) work, so you need to make the entire line this: url.rewrite-if-not-file = ( "^/-/([^\?]*)(\?(.*))?$" => "/-/$1/index.php?$3", "^/(.*)$" => "/index.php?token=$1" ) – Jonathan Kratzke Jul 8 '11 at 14:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.