Clean Drupal 7 install with workbench_moderation 7.x-1.3, pathauto 7.x-1.2 and redirect 7.x-1.0-rc1 modules, default settings - pathauto is configured to create a new alias and delete the old one, redirect is configured to create a redirect when an alias changes.

Steps to reproduce:

1 - Create a new moderated node (node/21, for example), in draft. Save. The node is aliased at /content/my-page-title-1.

2 - While still in draft, edit and change the page title. The node is now aliased at /content/my-page-title-2.
There is also a redirect from /content/my-page-title-1 to node/21. No problem so far.

3 - Publish the node. It will be publicly available at /content/my-page-title-2, and /content/my-page-title-1 will redirect to that. Still good.

4 - Edit the node and change the title, creating a new draft. This will now appear at /node/21/draft.
Note there is no new alias, as expected since the new draft is not published.
But redirect module has now created two new redirects, from /content/my-page-title-2 to /node/21, and from /content/my-page-title-3 to /node/21

5 - Visit the "view published" tab - /content/my-page-title-2.
This creates an infinite redirect loop due to the conflicting redirects. This is the page website visitors will see ... not good.

I suspect the additional node_save() calls are causing this?

Comments

johnpitcairn’s picture

With latest redirect dev, the notice is now a warning, so at least that can be hidden by not displaying warnings onscreen. The underlying issue - of a redirect being created for both current and draft revisions - still exists.

hass’s picture

Status: Active » Closed (duplicate)

Use redirect beta4. This is a known bug in redirect module.

Duplicate of #1796596: Fix and prevent circular redirects

johnpitcairn’s picture

Title: Infinite redirect loop with pathauto/redirect default settings » Redirects incorrectly created when saving as draft (using pathauto/redirect default settings)
Status: Closed (duplicate) » Active

OK - though there are still two unnecessary redirects created at the draft stage. Ideally the first should not be created until the draft is published, and the second should not be created at all.

The patch at #48 in #1796596: Fix and prevent circular redirects will also prevent the circular redirect warnings if applied to current redirect 7.x-dev.

But for Workbench Moderation workflows, both solutions merely hide the symptom, they do not fix the underlying problem. Changing this issue title accordingly, and re-opening.

stborchert’s picture

Quickfix: create a custom module (i.e. redirect_fix) and add the following hook-implementations:

<?php


/**
 * Implements hook_redirect_presave().
 */
function redirect_fix_redirect_presave($redirect) {
  // Remove redirects pointing to aliases of the node it handles.
  $query = db_select('url_alias', 'u')
          ->fields('u', array('alias'));
  $query->join('redirect', 'r', 'u.alias = r.source');
  $query->fields('r', array('rid'));

  $results = $query->execute();
  foreach ($results as $record) {
    db_delete('redirect')
            ->condition('rid', $record->rid)
            ->execute();
  }
}

/**
 * Implements hook_redirect_insert().
 */
function redirect_fix_redirect_insert($redirect) {
  redirect_fix_redirect_presave($redirect);
}

/**
 * Implements hook_redirect_update().
 */
function redirect_fix_redirect_update($redirect) {
  redirect_fix_redirect_presave($redirect);
}
?>
emilyf’s picture

subscribe

aschiwi’s picture

Status: Closed (duplicate) » Active

Thank you John Pitcairn for the steps to reproduce. A client kept reporting the redirect problem and we couldn't reproduce. The fix by stBorchert works well for us.

Coornail’s picture

Status: Active » Closed (duplicate)

Status: Active » Closed (duplicate)