prevent index.php from being presented in Drupal 8 URLs to preserve beauty and prevent SEO hits

Here’s the commit diff from another project where we saw that, titled “Least scary code to redirect just extraneous index.php/”

   RewriteCond %{QUERY_STRING} (.*(?:^|&))tag=([^&]*)&?(.*)&?$
   RewriteRule (.*)            /search?terms=%2 [L,NC,R]

+  RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
+  RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
   # Redirect common PHP files to their new locations.
   RewriteCond %{REQUEST_URI} ^(.*)?/(install.php) [OR]
   RewriteCond %{REQUEST_URI} ^(.*)?/(rebuild.php)

Add the part that starts with pluses (but don’t include the pluses) to your index.php and let us know how it works. May be worth an Agaric blog post but i don’t know what’s actually why this is happening either.


ben Agaric · · 508 283 3557

On 07/17/2018 08:53 PM, Steve Arone wrote:

Hi Ben, Micky, Chris,

I’m having an issue with in that index.php is not always being rewritten as a clean url.


should rewrite to:

After a search, I looked at this:

But not exactly sure what to do or if it is really an exact match for the problem.

I put a copy of the .htaccess file here:

Any help would be appreciated.