From 8ebb4dd181c6e3b946ebfe6144977dc25c685686 Mon Sep 17 00:00:00 2001 From: Zach Parrott Date: Wed, 18 Nov 2015 09:55:57 -0600 Subject: [PATCH 1/2] Fixed issue where external redirects were not working correctly due to the scope of the referenced object which caused comparing of unintended records. --- redirectmanager/services/RedirectManagerService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/redirectmanager/services/RedirectManagerService.php b/redirectmanager/services/RedirectManagerService.php index 6695191..113ebe5 100644 --- a/redirectmanager/services/RedirectManagerService.php +++ b/redirectmanager/services/RedirectManagerService.php @@ -51,8 +51,13 @@ public function processRedirect($uri) $redirectLocation = $record['location']; } } + //If a matching redirect is found set the record and exit the loop + if(isset($redirectLocation)){ + $recordMatch = array("url" => ( strpos($record['location'], "http") === 0 ) ? $redirectLocation : UrlHelper::getSiteUrl($redirectLocation), "type" => $record['type']); + break; } - return (isset($redirectLocation)) ? array("url" => ( strpos($record['location'], "http") === 0 ) ? $redirectLocation : UrlHelper::getSiteUrl($redirectLocation), "type" => $record['type']) : false; + } + return (isset($recordMatch)) ? $recordMatch : false; } public function newRedirect($attributes = array()) From 5ee72495d5233e34886ab57f525a0b2815d6d8ec Mon Sep 17 00:00:00 2001 From: Zach Parrott Date: Wed, 18 Nov 2015 09:56:35 -0600 Subject: [PATCH 2/2] Added ability to globally configure ignoring case sensitivity for redirects through the plugin's configuration file. --- README.md | 17 ++++++++++++ .../services/RedirectManagerService.php | 26 +++++++++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ed4db46..f2adf1a 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,23 @@ Keep all your 301/302 managed within Craft. Very useful when using NGINX because * Upload to plugins/redirectmanager * Install Plugin (Settings -> Plugins -> Redirect Manager) +## Configuration +Configuration File Locations: + +* config.php under craft/plugins/redirectmanager +* redirectmanager.php under craft/config + +Options: + +* ignoreCase (Boolean) - If set to true redirects will ignore case sensitivity. Defaults to false. + +##### Example config.php/redirectmanager.php: +` true, + ); +?>` + ## Usage #### Regex diff --git a/redirectmanager/services/RedirectManagerService.php b/redirectmanager/services/RedirectManagerService.php index 113ebe5..6e22a1a 100644 --- a/redirectmanager/services/RedirectManagerService.php +++ b/redirectmanager/services/RedirectManagerService.php @@ -20,6 +20,10 @@ public function processRedirect($uri) $records = $this->getAllRedirects(); $doRedirect = false; + //Check plugin configuration for case insensitivity + $ignoreCase = $this->isCaseInsensitive(); + + foreach($records as $record) { $record = $record->attributes; @@ -41,21 +45,22 @@ public function processRedirect($uri) $regex_match = true; } if ($regex_match) { - if(preg_match($record['uri'], $uri)){ - $redirectLocation = preg_replace($record['uri'], $record['location'], $uri); + //Change record's URI RegEx if ignore case + $recordUriRegex = ($ignoreCase) ? $record['uri']."i" : $record['uri']; + if(preg_match($recordUriRegex, $uri)){ + $redirectLocation = preg_replace($recordUriRegex, $record['location'], $uri); } } else { - // Standard match - if ($record['uri'] == $uri) - { - $redirectLocation = $record['location']; - } + // Standard match case insensitive + if( ($record['uri'] === $uri) OR ($ignoreCase && strtolower($record['uri']) === strtolower($uri)) ){ + $redirectLocation = $record['location']; + } } //If a matching redirect is found set the record and exit the loop if(isset($redirectLocation)){ $recordMatch = array("url" => ( strpos($record['location'], "http") === 0 ) ? $redirectLocation : UrlHelper::getSiteUrl($redirectLocation), "type" => $record['type']); break; - } + } } return (isset($recordMatch)) ? $recordMatch : false; } @@ -119,4 +124,9 @@ private function _processWildcardMatch($val) { } + + private function isCaseInsensitive(){ + $ignoreCase = craft()->config->get('ignoreCase', 'redirectmanager'); + return ($ignoreCase != null && $ignoreCase == true); + } }