I have a Drupal 8 site with clean URLs. Recently, URLs are similar to example.com/index.php/page-url-alias. The page still loads correctly, but I don't want the index.php part to be indexed.

If I empty the cache, the URLs are shown correctly.

How can I force Drupal not to add index.php in the URLs it generates?

  • So when do they appear with index.php then if you cleared the cache? Maybe some wring custom links?
    – schlicki
    Commented Feb 17, 2017 at 7:25
  • @schlicki No, they disappear when the cache is cleared. The path aliases all look good.
    – Tim
    Commented Feb 17, 2017 at 10:37
  • But then its fine isn't it? Or when do they show up wrong again?
    – schlicki
    Commented Feb 17, 2017 at 11:49
  • They show up again eventually.
    – Tim
    Commented Feb 17, 2017 at 11:57
  • Yes, that's a strange behavior in D8, very erratic and unpredictably. And this poisons all other internal links in the browser session. You can fix this with the module Redirect, see my answer. Does anybody know where this is coming from? You shouldn't need a module to fix this.
    – 4uk4
    Commented Feb 19, 2017 at 9:30

2 Answers 2


In D7 Global Redirect was used for clean urls. In D8 this was moved to the module Redirect.

The global redirect options in Redirect are set by default to avoid unclean urls:

enter image description here


Might not be a clean way but you could do this via your .htaccess, Something along the lines of this:

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

Not sure if this works in drupal, i have used this on other CMS.

  • I thought about mod_rewrite as an interim solution, I was wondering if there is a Drupal-specific way of preventing it.
    – Tim
    Commented Feb 17, 2017 at 7:19

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.