Hola Paul!

> Trying to port my apache rewrite configuration to cherokee I got
> confused with the handler directives, specially with the redir
> handler.  And I am not able to debug my tries as the logfiles do not
> contain anything about the internal server errors I get.  I think I
> did not get the concept of the cherokee handlers yet.

  Okay, let me explain if briefly.  A handler is a content generator,
  basically it is a module that, in some way, "creates" the content
  that you are going to send back to the client.  In the default
  distribution of Cherokee there are a number of handlers; the most
  important ones are:

    - file:  It generates the content by reading the files. In other
      words, it reads the file that the client is requesting and sends
      it.  No more, no less.

    - dirlist:  It makes lists with the content of the directory the
      the user is requesting.  It only works if the user is requesting
      a directory, and the only think it does is to build the content
      list.

    - fcgi:  It implements the communication with a FastCGI server, so
      in order to "generate" some content, it query the FastCGI
      server, and the output it gets from it is the content the the
      server is delivering.

    - redir:  It generates no real content. The only thing this
      handler does is to redirect the user request to somewhere else.
      The rules that it checks for the redirection are defined why the
      server configuration, so actually it is up to you how and where
      the server will redirect the request.

    - cgi:  It executes CGI files in order to get some output from
      them to reply the client.

    .. and so on, and so on.

   So, the handler implements basically behaviours of the server: what
   the server does in order to reply clients.

   What you do in the Cherokee configuration file, is define where to
   apply each one of those behaviours.  Currently you have many ways
   to do it:

     - Directories:  You can set a handler in a directory. For
       example:

          Directory /icons {
             Handler file
          }

          which means: "Everything inside the /icons web directory must
          be threaten as files. The server mustn't do anything but read
          the requested file and send it back to the client".

     - Extensions:  You can also define the behavior of certain
       extensions.  For example:

          Extension php, php4 {
             Handler fcgi {
            # FastCGI config
                }
          }

        - Requests:  You can even define a handler based on the request
       that the client send.  It accepts regular expressions, so
       actually this method is pretty flexible. Example:

          Request "^/test/[^!]+$" {
             Handler whatever
          }

          And I think it's here where is gets confusing for you.  There
          is a really handy way in you can define redirections using
          request entries and the redir handler.  For example:

          Request "^/photo/(.*)/(.*)$" {
             Handler redir {
                  Rewrite "/index.php?q=showpic&pic=$1.jpg&size=$2"
                }
          }
        
          and that is going to redirecto /photo/first/big to:
          "/index.php?q=showpic&pic=first.jpg&size=big".  If be some
          reason you want to make and HTTP redirection to the new URL
          rather than and internal one, you only have to change "Rewrite"
          by "Show Rewrite", that is all.

> The handler directive can be everywhere, in Directory directives,
> Request, etc. Is it possible to use it just within a Server directive?

  Inside a Server directive you can use as many Directory, Extension
  and Request entries as you want, there isn't any kind of limitation.

  The only rule is that, at least you must define the Directory /.
  That directory has the special meaning of being the default option
  for the server.  If any of the previous rules matched it will use
  that one as the last option.

> The examples in the documentation just show the use of the redir handler
> in a specific directory (Directory /photos). Is it possible to use it in
> the root directory? Do I have to use the Request directive then or is it
> possible to do it without?

  You can use any of the handlers in any of the three types of
  entries.  Actually, it's up to you how to configure it. The most
  common practice is to use redir inside Request entries, but as I
  said, depends on you needs.

> I want to redirect, for example, myserver/action1 to
> myserver/index.php?do=action1 and the same with action2, action3,
> etc.  Is it necessary to create a Request directive for each of
> them? Or is there a way to make it more generally?

  Yep, I would do that. Something like this should work:

  Request "^(.*)$" {
     Handler redir {
       Rewrite "/index.php?do=$1"
        }
  }

  Extension php {
     Handler fcgi {
          # The FastCGI config in here
        }
  }

  You have to remember that *the order in which you write the
  configuration entries matters*. It is really important to take that
  in mind: the latest entries have a higher priority than the first
  ones.

  So, in the previous example, the PHP extension has a higher priority
  than the Request redirection.  In that way, if you try to execute
  something ending in php it will work, but if you try to access
  something else it will use the redirection.

> Do I have to use "URL ..."? Why that? I want the server to fallback
> to the common handler if he does not find any suitable redirection
> patterns.

  No, it is meant be used only in the embedded version.


-- 
Greetings, alo.
http://www.alobbs.com

_______________________________________________
Cherokee mailing list
[email protected]
http://www.0x50.org/cgi-bin/mailman/listinfo/cherokee

Reply via email to