Search code examples
phpregexkohanalighttpd

url.rewrite-once with Kohana and with urls


Currently I have this setup in our simple-hosts.conf:


url.rewrite-once = (
    ".*.(js|ico|gif|jpg|png|css|php|htm)(?.*)?$" => "$0",
    "/slapi" => "/slapi/index.php"
)

Works great, except the above fails when I have a dot in the query string:

?url=http://google.com


Solution

  • Why not just use the server.error-handler-404 = "/path/to/index.php"?

    But as for the regex itself, you have many unescaped characters in there. The second . I'm assuming you mean as a literal .. If so, you need to escape it with a backslash \.. The same goes with the ? character (which again, I'm assuming you mean a literal ?). So the regex should be:

    ".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*)?$"
    

    Plus, you could improve it even more by removing the question mark around the query pattern (I prefer this syntax, I find it easier to read):

    ".*\\.(js|ico|gif|jpg|png|css|php|htm)(\\?.*|)$"