Created
January 6, 2012 04:55
-
-
Save enminc/1569067 to your computer and use it in GitHub Desktop.
Quick and dirty query sting redirector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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