there is quite difference when u run localhost/gii then it assumes that there is directory with named gii under www/(web Root) but there is nothing like that, so it generates error.
but when you run localhost/index.php/gii then it access first the web like project index page(which u set up in server configuration) then called its gii component respectively.
but this is not correct way to use yii application. you have to put installed yii directory inside htdocs folder then access it by using localhost/yii then it automatically access yii default application. then used gii tool in appropriate manner.