rewrite the index to latest when needed