I am trying Yii out on a lighttpd system and was wondering if anyone could help me out with the rewrite rules for friendly urls.
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Any help translating this into something lighttpd could understand?
There is another way to do it. In my opinion Yii (the application itself) should take care of rewrite rules - not the webserver. So I searched for a solution and found Lighttpd’s mod_magnet. With a lua-script you can implement Apache’s “is-file-available?”-condition.
Here a short how to:
Make sure lighttpd is compiled with lua support
Make sure mod_magnet and mod_rewrite are enabled in the lighttpd config (magnet before rewrite!)
Save this as a new file called "rewrite.lua" and put it in your lighttpd config file folder:
function file_exists(path)
local attr = lighty.stat(path)
if (attr) then
return true
else
return false
end
end
if (lighty.env["request.uri"] == "/" or not file_exists(lighty.env["physical.path"])) then
lighty.env["physical.rel-path"] = "/index.php"
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end