Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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]
</IfModule>
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 - packtpub.com/article/migration-from-apache-to-Lighttpd 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
add comment

1 Answer

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:

http://drupal.org/node/43782

However, it looks like there is support now:

http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModRewrite#urlrewrite-repeat-if-not-file

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 ( yourdoma.in/- ) 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
add comment

Your Answer

 
discard

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.