Skip to content

Instantly share code, notes, and snippets.

@enminc
Created January 6, 2012 04:55
Show Gist options
  • Save enminc/1569067 to your computer and use it in GitHub Desktop.
Save enminc/1569067 to your computer and use it in GitHub Desktop.
Quick and dirty query sting redirector
/*
Quick plugin I just wrote to redirect querystring based uri's used in old site to new modx resource location.
Not intended to be anything more then a quick fix until search engines are no longer indexing the old links.
Might be useful in helping someone learn how to write a dynamic 301 redirect
*/
/*
NOTE: For a more robust controller I would recommend you checkout http://modx.com/extras/package/simplxcontroller by larscwallin
*/
if(substr_count($_SERVER['REQUEST_URI'],'/gallery/gallery.php') > 0){
if(!empty($_GET['id'])){
$doc = $modx->getObject('modResource',array('alias'=>$_GET['id']));
if($doc){
$docId = $doc->get('id');
$target = $modx->makeUrl($docId);
$target = $modx->getOption('site_url').$target;
$modx->log(modX::LOG_LEVEL_INFO, 'Redirecting old gallery link to new');
header('HTTP/1.1 301 Moved Permanently');
$modx->sendRedirect($target);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment