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 6695191..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,18 +45,24 @@ 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($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()) @@ -114,4 +124,9 @@ private function _processWildcardMatch($val) { } + + private function isCaseInsensitive(){ + $ignoreCase = craft()->config->get('ignoreCase', 'redirectmanager'); + return ($ignoreCase != null && $ignoreCase == true); + } }