10

I write 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?

3
  • Please check my answer. Commented Oct 20, 2016 at 5:12
  • @NikunjVadariya basically your answer and denish answer is the same :)
    – Seventh St
    Commented Oct 20, 2016 at 6:50
  • Yes, but I answer you first. NP :) Commented Oct 20, 2016 at 6:52

3 Answers 3

19

URL rewrites will remove index.php from url

How to enable URL rewrites?

1   Stores > Configuration > Web
2   expand the Search Engine Optimization section
3   set Use Web Server Rewrites to “Yes.”
4   When complete, tap Save Config

Hope this will help you.

4
  • and then bin/magento setup:upgrade
    – popeye
    Commented Sep 8, 2018 at 19:28
  • setup:upgrade for a config change? Surely not. Commented Feb 8, 2020 at 14:06
  • just need to reindex and clear cache after.
    – Jonathan
    Commented Aug 19, 2021 at 20:05
  • Stores > Configuration > General > Web. 'Web' tab is under 'General' Tab.
    – Felix H.
    Commented Oct 19, 2021 at 17:25
2

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.

Edit the /rootdir/.htaccess and uncomment the line:

RewriteBase /magento2/

In my case the subdirectory Magento is in is called magento2, so change it to your subdirectory path if it is different.

1

Magento 2.2: Add below line in .htaccess File

AddHandler application/x-httpd-php70 .php .php5 .php4 .php3

After that enable URL Rewrites from Admin:

  1. Stores>Configuration> Web
  2. Expand the Search Engine Optimization section
  3. Set Use Web Server Rewrites to “Yes.”
  4. When complete, tap Save Config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.