Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
`<?php
return array(
'ignoreCase' => true,
);
?>`

## Usage

#### Regex
Expand Down
31 changes: 23 additions & 8 deletions redirectmanager/services/RedirectManagerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down Expand Up @@ -114,4 +124,9 @@ private function _processWildcardMatch($val)
{

}

private function isCaseInsensitive(){
$ignoreCase = craft()->config->get('ignoreCase', 'redirectmanager');
return ($ignoreCase != null && $ignoreCase == true);
}
}