url rewriting: take longest and first match