Cherokee Web Server: Redirections

Redirections

The main idea of a redirection is telling to the web client to go to another URL when the request URL matchs some rule.


For example, if you have URLs like


You probably would prefer URLs like:


Parameters

The redir handler accepts two directives:

Examples

This example will perform a hidden redirection:

Directory /photo {
    Handler redir {
        Rewrite "/(\d+)$" "http://example.com/inst/photogallery/viewphoto?photoid=$1"
        Rewrite "/(\d+)/cmts" "http://example.com/viewcomments?photoid=$"
        Rewrite "/(\d+)/delete" "http://example.com/inst/photogallery/admin?photoid=$1&method=delete"
        URL http://example.com/notfound?url=
    }
}


In the case you want to use an HTTP redirection, this is the right entry:

Directory /photo {
    Handler redir {
        Show Rewrite "/(\d+)$" "http://example.com/inst/photogallery/viewphoto?photoid=$1"
        Show Rewrite "/(\d+)/cmts" "http://example.com/viewcomments?photoid=$"
        Show Rewrite "/(\d+)/delete" "http://example.com/inst/photogallery/admin?photoid=$1&method=delete"
        URL http://example.com/notfound?url=
    }
}