Skip to content

Commit

Permalink
[Improved] Try redirects both with and without the query string
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welch committed Sep 1, 2016
1 parent 3a15e37 commit 48e0c47
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions RetourPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public function init()
/* -- See if we should redirect */

$url = urldecode(craft()->request->getRequestUri());
$url = UrlHelper::stripQueryString($url);
$redirect = craft()->retour->findRedirectMatch($url);
$noQueryUrl = UrlHelper::stripQueryString($url);

/* -- Redirect if we find a match, otherwise let Craft handle it */

/* -- Redirect if we found a match, otherwise let Craft handle it */
$redirect = craft()->retour->findRedirectMatch($url);

if (isset($redirect))
{
Expand All @@ -49,7 +50,22 @@ public function init()
craft()->request->redirect($redirect['redirectDestUrl'], true, $redirect['redirectHttpCode']);
}
else
craft()->retour->incrementStatistics($url, false);
{

/* -- Now try it without the query string, too, otherwise let Craft handle it */

$redirect = craft()->retour->findRedirectMatch($noQueryUrl);

if (isset($redirect))
{
craft()->retour->incrementStatistics($url, true);
$event->handled = true;
RetourPlugin::log("Redirecting " . $url . " to " . $redirect['redirectDestUrl'], LogLevel::Info, false);
craft()->request->redirect($redirect['redirectDestUrl'], true, $redirect['redirectHttpCode']);
}
else
craft()->retour->incrementStatistics($url, false);
}
}
}
};
Expand Down

0 comments on commit 48e0c47

Please sign in to comment.