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.

best,

ben Agaric · http://agaric.com · 508 283 3557

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

Hi Ben, Micky, Chris,

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

example:

https://k12playground.com/index.php/search/organizations/pa

should rewrite to:

https://k12playground.com/search/organizations/pa

After a search, I looked at this:

https://www.drupal.org/forum/support/post-installation/2016-09-19/how-to-remove-indexphp-from-urls

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:

https://pastebin.com/n3a1YqEe

Any help would be appreciated.

Thanks,

Steve