I want any requests like http://example.com/whatever/index.php, to do a 301 redirect to http://example.com/whatever/.
http://example.com/whatever/index.php
http://example.com/whatever/
I tried adding:
Keep the first slash out of the match :
rewrite ^/(. +)/index.php$ $scheme://$1/ permanent;