# Rewrite rules for lighttpd
# These are experimental and are included for your convenience if you use lighttpd. No promises.

server.modules   += ( "mod_rewrite", "mod_redirect" )

# path to your zenphoto installation in the webroot
# don't forget the trailing slash!
var.zendir = "/zenphoto/"
# Mod_rewrite Image suffix, see admin/options/gallery configuration
# don't forget to escape special characters (like .)
var.suffix = "\.php"

# change the hostname to match yours
$HTTP["host"] =~ "www\.exemple\.org" {
    url.rewrite-once = (
         # "Static" pages
         "^"+zendir+"(admin|albums|cache|themes|zp-core|rss).*$" => "$0",
         # This is already a constructed request
         "^"+zendir+"(index.php)?\?.*" => "$0",

         # Picture
         "^"+zendir+"(.*)/([A-Za-z0-9\-_\.]+)"+suffix+"$" => zendir+"index.php?album=$1&image=$2",
         # Picture with query
         "^"+zendir+"(.*)/([A-Za-z0-9\-_\.]+)"+suffix+"\?(.+)$" => zendir+"index.php?album=$1&image=$2&$3",
         # Album
         "^"+zendir+"([^/]+)/$" => zendir+"index.php?album=$1",
         # Album with query
         "^"+zendir+"(.+)/\?(.+)$" => zendir+"index.php?album=$1&$2",

         # Multipages
         "^"+zendir+"page/([0-9]+)/?$" => zendir+"index.php?page=$1",
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/?$" => zendir+"index.php?p=$1",
         "^"+zendir+"(.+)/page/([0-9]+)/?$" => zendir+"index.php?album=$1&page=$2",    

         # For fields (?)
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/fields([0-9]+)/(.+)/([0-9]+)/?$" => zendir+"index.php?p=$1&searchfields=$2&words=$3&page=$4",
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/fields([0-9]+)/(.+)/?$" => zendir+"index.php?p=$1&searchfields=$2&words=$3",
         # For archive-/date-search
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/archive/([A-Za-z0-9\-_]+)/([0-9]+)/?$" => zendir+"index.php?p=$1&date=$2&page=$3",
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/archive/([A-Za-z0-9\-_]+)/?$" => zendir+"index.php?p=$1&date=$2",
         # For tags
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/tags/(.+)/([0-9]+)/?$" => zendir+"index.php?p=$1&searchfields=4&words=$2&page=$3",
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/tags/(.+)/?$" => zendir+"index.php?p=$1&searchfields=4&words=$2",
         # For search
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-_]+)/([0-9]+)/?$" => zendir+"index.php?p=$1&words=$2&page=$3",
         "^"+zendir+"page/([A-Za-z0-9\-_]+)/([A-Za-z0-9\-_]+)/?$" => zendir+"index.php?p=$1&words=$2",

         # Images
         "^"+zendir+"(.+)/image/(thumb|[0-9]{1,4})/([^/\\]+)$" => zendir+"zp-core/i.php?a=$1&i=$3&s=$2",
         "^"+zendir+"(.+)/image/([^/\\]+)$" => zendir+"zp-core/i.php?a=$1&i=$2",
                
         #### Catch-all - everything else gets handled in PHP for compatibility.
         "^"+zendir+"(.+)/?$" => zendir+"index.php?album=$1"
    )

    url.redirect = (
        "^"+zendir+"admin" => zendir+"zp-core/admin.php"
    )
}
