[SOLVED] Lighttpd Rewrite

Hi :)

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?

Thanks

Chris

Answering my own question :)




url.rewrite-once = (

        "^\/(images|assets)(.*)$" => "$0",

        "^/(.*)" => "/index.php"

)



Perhaps place this in the Yii documentation for others who are using Lighty?

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

  • In your lighttpd config file add this:



$SERVER["socket"] == ":80" {

  magnet.attract-physical-path-to = ( "/path-of-lighttpd-config-file-folder/rewrite.lua" )

}

Now it should work exactly like Apache. Hope this helps someone. I may add it to the cookbook soon.

It’s a long time ago since this post, but you have forgot to protect the directory “protected” and what is with the directory css :) !?

Add:


$HTTP["url"] =~ "^/protected/" {

        url.access-deny = ( "" )

    }



Sry. My english is horrible ::) ;)

A full example:


$HTTP["host"] == "example.com" {


    server.document-root = "/your/path/www/yii_root"

    server.name = "example.com"

    dir-listing.activate = "disable"


    $HTTP["url"] =~ "^/protected/" {

        url.access-deny = ( "" )

    }


    index-file.names = ( "index.php", "index.html" )


url.rewrite-once = (

        "^\/(images|assets|css)(.*)$" => "$0",

        "^/(.*)" => "/index.php"

)

Greetz Terrahawk

http://www.yiiframework.com/forum/index.php?/topic/6977-removing-index-php-in-url-with-other-webservers/

Here’s another way, using url.rewrite-if-not-file instead of url.rewrite-once.

Just to keep things together, :)