Lighttpd – url rewrite and query string QSA

One of the first things I was curious about when I started using Lighttpd was url-rewrites. On apache mod_rewrites you can use the [QSA] flag to allow for the query string after your new urls. Here is the equivalent in lighttpd. This would go in your lighttpd.conf file which is usually located in /etc/lighttpd/lighttpd.conf on your server.

                url.rewrite-once = (
                        "^/browse/files(?:\?(.*))?"  =>  "/somefile.php?$1"

The important part is the (?:\?(.*))? pattern which matches (optionally) any query string and forwards it to your php file. If you do not have this code, your new url will return a 404 error for any query strings appended to the new url.

, ,