echo $block->getBaseUrl() in my .phtml template, and show output http://localhost/magento2/index.php/. I want to remove
index.php from that output. How can i do that?
You can remove the index.php in the frontend URLs performing the following steps in Magento's admin section:
In System -> Configuration -> Web -> Search Engines Optimizations, select YES.
/rootdir/.htaccess and uncomment the line:
In my case the subdirectory Magento is in is called
magento2, so change it to your subdirectory path if it is different.