MODx Plugin for Resource Redirecting

So Abraham got to work and adapated the example Page Not Found MODx Plugin to work as follows: domain.com/19 forwards to (301) domain.com/category/resource-19-alias.html .

The Plugin Code

Create a new plugin, name it whatever you'd like resourceRedirect. Then on System Events check OnPageNotFound.

    <?php
if ($modx->event->name == 'OnPageNotFound') {
$output = '';
$param_alias = $modx->getOption('request_param_alias');
$get = $modx->getOption('GET', $modx->request->parameters, '');
$rId = $modx->getOption($param_alias, $get, '');
if(!is_numeric($rId)) {
41return $output;
}
$rId = intval($rId);

$resource = $modx->getObject('modResource', array('id'=>$rId));

if($resource) {

$url = $modx->makeUrl($resource->get('id'));
$modx->sendRedirect($url);

return $output;
}
} 

Recent Posts

Improving MODX Page Speed for Google

Your website speed is impacting your bottom line , here are a few ways to improve it through browser caching, asynchronous loading of resources and other tips and tricks.

The Status of Liquid Web Cloud Sites Formerly of Rackspace in 2018

We've been a cloudsites customer since our inception, it's had ups and downs, here is what we think about it now.

OG Image Branding with phpThumb and MODX

Some of our clients have wanted to make sure their logo and branding appear in facebook, twitter, or messaging apps when shared. We came up with a clever solution.