Hey all. I needed to setup a bunch of redirects for a site I was just deploying and didn’t find a plugin that was working fully correctly. Using NG!Redirect as a base I modified it for it to work for me on 1.0.2. Hopefully others will find this useful. In comments at top I did reference the old plugin, hopefully that is the correct way of crediting the original author.
To install Create a new plugin:
Name: Redirects
Description: <strong>0.0.3</strong> Redirects old URL’s to the new ones
Paste in code below
Edit $sites array with your old pages and docid to redirect to
On system events tab select OnPageNotFound
/*####
#
# Name: Redirect
# Author: Three Eyed Bird Design
# http://www.threeeyedbird.com
# Version: 0.0.3
# Date: 1/8/10
# Based on original plugin NG!Redirect version 0.0.2 by
# Stefan Bruggmann - http://www.ng-projects.ch
#
####
#
#
# Usage:
# Enter your old Site-Names and the new static ones or dynamic id's to the following array like..
#
# Example:
# $sites = array(
# 'The-Old-URL' => 6,
# 'Another-Old-URL' => 'A-New-Hard-Link'
# );
#
####
*/
$sites = array(
'/oldpage.html' => 1,
'/contactustoday.html' => 6,
);
$e = &$modx->event;
if($e->name == "OnPageNotFound")
{
//Get Current URL
$current = $_SERVER["REQUEST_URI"];
foreach( $sites as $k => $v ){
if( $k==$current ){
if( is_numeric($v) ){
$obj = $modx->getDocumentObject('id', $v);
$url = $obj['alias'].$modx->config['friendly_url_suffix'];
}else{
$url = $v;
}
$this->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
exit;
}
}
}