--- path_redirect.module 2008-03-04 21:27:06.000000000 -0600
+++ path_redirect.module 2008-03-06 08:15:50.000000000 -0600
@@ -33,14 +33,14 @@ function path_redirect_init() {
if (preg_match('/^\?q=/', $path)) {
$path = preg_replace(array('/^\?q=/', '/&/'), array('', '?'), $path, 1);
}
- $r = db_fetch_object(db_query("SELECT redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path)));
+ $r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path)));
if (!$r) {
$path = preg_replace('/\?.*/', '', $path);
- $r = db_fetch_object(db_query("SELECT redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path)));
+ $r = db_fetch_object(db_query("SELECT rid, redirect, query, fragment, type FROM {path_redirect} WHERE path = '%s' OR path = '%s'", $path, utf8_encode($path)));
}
// only redirect if allow_bypass is off or bypass is not requested
- if ($r && !(variable_get('path_redirect_allow_bypass', 0) && !empty($_GET['redirect']) && $_GET['redirect'] == 'no')) {
+ if ($r && !(variable_get('path_redirect_allow_bypass', 0) && !empty($_GET['redirect']) && $_GET['redirect'] == 'no') && url($r->redirect) != url($path)) {
if (variable_get('path_redirect_redirect_warning', 0)) {
drupal_set_message(t('This page has been moved. You may want to update your bookmarks.'));
}
@@ -54,6 +54,11 @@ function path_redirect_init() {
path_redirect_goto($r->redirect, ($r->query ? $r->query: NULL), ($r->fragment ? $r->fragment : NULL), $r->type);
}
}
+ else if (url($r->redirect) == url($path)) {
+ // warn about cyclical redirects
+ watchdog('path_redirect', t('Redirect to %redirect is causing an infinite loop; redirect cancelled.', array('%redirect' => $r->redirect)), WATCHDOG_WARNING, l(t('edit'), 'admin/build/path-redirect/edit/'. $r->rid));
+ return;
+ }
else if ($r && variable_get('path_redirect_allow_bypass', 0) && !empty($_GET['redirect']) && $_GET['redirect'] === 'no') {
drupal_set_message(t('This page is redirected to:') .' '. l($r->redirect, $r->redirect, ($r->query ? $r->query: NULL), ($r->fragment ? $r->fragment : NULL)) .'');
}