Skip to content

Instantly share code, notes, and snippets.

@matdave
Created October 19, 2018 18:58
Show Gist options
  • Save matdave/f136f9024028a6d04406644c6ac19be3 to your computer and use it in GitHub Desktop.
Save matdave/f136f9024028a6d04406644c6ac19be3 to your computer and use it in GitHub Desktop.
Evo to Revo URI Plugin
<?php
/**
** OnPageNotFound
**/
$URI = $_SERVER['REQUEST_URI'];
if(strpos($URI, '.html') !== false){
$URI = ltrim(str_replace('.html','/',$URI), '/');
$resource = $modx->getObject('modResource', array('uri:='=>$URI, 'context_key:='=> $modx->context->key));
if(!empty($resource)){
$modx->sendRedirect($modx->makeUrl($resource->id, $modx->context->key, '', 'full'), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
}
}else{
$URI = ltrim($URI, '/').'.html';
$resource = $modx->getObject('modResource', array('uri:='=>$URI, 'context_key:='=> $modx->context->key));
if(!empty($resource)){
$modx->sendRedirect($modx->makeUrl($resource->id, $modx->context->key, '', 'full'), 0, 'REDIRECT_HEADER', 'HTTP/1.1 301 Moved Permanently');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment