How do I redirect users visiting a path matching a regular expression? My question is the same asked in How do I redirect from /index.php/event/* to /event? but for Drupal 8.

Since the module suggested in the accepted answer for that question doesn't have a version for Drupal 8, how can I achieve the same with Drupal 8?
In Drupal 8 you use an event subscriber for this. You subscribe to a REQUEST kernel event, get the original url from the request, apply a regular expression and if this finds a replacement set the new url as a 301 redirect response.

mymodule/src/EventSubscriber/RedirectSubscriber.php

&lt;?php

namespace Drupal\mymodule\EventSubscriber;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Symfony\Component\HttpKernel\KernelEvents;

class RedirectSubscriber implements EventSubscriberInterface {

  public function redirectIndexPHP(GetResponseEvent $event) {
    $old_url = $event-&gt;getRequest()-&gt;getUri();
    $new_url = preg_replace('|/index.php|', '', $old_url, 1, $count);
    if ($count &gt; 0) {
      $response = new TrustedRedirectResponse($new_url, 301);
      $event-&gt;setResponse($response);
    }
  }

  static function getSubscribedEvents() {
    $events[KernelEvents::REQUEST][] = array('redirectIndexPHP', 39);
    return $events;
  }

}


mymodule/mymodule.services.yml

services:
  mymodule.redirect:
    class: Drupal\mymodule\EventSubscriber\RedirectSubscriber
    arguments: []
    tags:
      - { name: event_subscriber }