23 Aug.2019

Drupal 10: Remove all redirect entities from the site programmatically

Drupal Redirects

Sometimes we need to completely remove redirect entities, for example, when you copy a site for another project.

You can use custom code in your custom module or install devel_php and run with admin interface on /devel/php.

$ids = \Drupal::entityQuery('redirect')->execute();
$ids = \Drupal::entityQuery('redirect')->execute();
$storageHandler = \Drupal::entityTypeManager()->getStorage('redirect');
$entities = $storageHandler->loadMultiple($ids);
foreach ($entities as $entity) {

Ruslan Piskarov

PHP/WEB Developer / Drupal Expert. More than 11 years of experience delivering Drupal based General Purpose solutions for different sectors such as Job Boards, Product Portfolios, Geo Coding, Real Estate solutions, E-Commerce, Classifieds, Corporate and online Magazines/Newspapers.