Thursday, December 31, 2009

How to mimic apache's "!-f" and "!-d" in lighttpd

Just a while ago, I was still trying to write a php script to load static content and send them to browser, now that I know apache has a nice rewrite condition like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d<
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I don't have to use that script of mine any more. However, I hit the wall straight on when I was trying to port the same functionality in lighttpd, and the only thing I found was
url.rewrite-[repeat-]if-not-file
Only half of the solution, and it somehow stopped working for me after working or 2 weeks, and says
WARNING: unknown config-key: url.rewrite-if-not-file (ignored)
gerrr.....

That did it ;-) I was determined to find the right solution to finish this for good, and here is what I have found:

Using mod_magnet and a small lua script. For detail, see the following urls.

http://www.akelos.org/wiki/setting-up-akelos-on-lighttpd-in-a-mac
http://redmine.lighttpd.net/projects/lighttpd/wiki/AbsoLUAtion

Oh, if you happen to be on ubuntu, you would probably also need to do this
sudo apt-get install lighttpd-mod-magnet

Monday, December 28, 2009

ubuntu's rc management

I hate to write these down, but I have been using these so often this winter break that I can't allow myself to do another search to find the answers.

To stop apache2 for this session only:
sudo /etc/init.d/apache2 stop

To remove apache2 permanently from startup scripts:
sudo update-rc.d apache2 remove

To reinstate apache2 in the startup scripts:
sudo update-rc.d apache2 defaults