Redirect to HTTPS except localhost

It could be a good idea. I do not know what is the best solution.