I am working on my client's project and they are using Drupal 8.

I discovered that when one uses http://example.com/index.php to access the webpage, the url generated by the menu items , the index.php part is included, i.e. http://example.com/index.php/aboutus instead of http://example.com/aboutus. And it leads to a wrong page.

And I checked with the template file which generates the menu, the url of the menu is generated by {{item.url}}, which item is one single item of items for the available variables in the menu templates.

Available variables:

-menu_name: The machine name of the menu.

-items: A nested list of menu items. Each menu item contains:

-attributes: HTML attributes for the menu item.

-below: The menu item child items.

-title: The menu link title.

-url: The menu link url, instance of \Drupal\Core\Url

-localized_options: Menu link localized options.

Therefore I am asking if there are ways to get rid of the "index.php" in this case and in order to avoid drupal generating wrong url? Thank you very much

2 Answers 2


I think you may need to enable apache mod_rewrite. You can refer this answer as well. To enable mod_rewrite, use the following command:

a2enmod rewrite

Then you need to restart apache for the changes to reflect,

sudo /etc/init.d/apache2 restart


sudo service apache2 restart

Refer this page for information about clean urls, this might even help.


Render the menu item using link() function in your twig file for example,

{{ link(item.title, item.url) }}

I hope, it would solve your issues

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.