phpregexrouteslighttpd

Need help forming several Lighttpd conditional redirects for PHP router


I am trying to set up a few conditional redirects for a lighttpd installation on Ubuntu. I would like the following:

https://www.example.com/clients/xyz
https://www.example.com/admin/xyz

To pass through normally, but something like:

https://www.example.com/abc123

To redirect to the "index.php" page at the web root, where I will inspect and act on the "abc123" portion of the URL. I would like all redirects to retain the query parameters (if any). I'm basically building a conditional router without having all requests hit "index.php".

Any assistance would be MUCH appreciated!

I read the documentation on the settings in "lighttpd.conf" regarding "mod_redirect" usage but I'm confused as to where to start.


Solution

  • It's a while since I used lighttpd, but you can match the specific ones you want using rewrite-once, then catch the rest with .* - e.g.

    $HTTP["host"] =~ "^www\.example\.com|example.com$" {
        url.rewrite-once = ( 
            "^/clients/(.*)" => "/clients/$1",
            "^/admin/(.*)" => "/admin/$1",
            "^/(.*)" => "/index.php/$1"
        )
    }