//event; if ($e->name == "OnPageNotFound") { // Retrieve requested path + alias $documentAlias = str_replace($modx->config['friendly_url_suffix'], '', $_REQUEST['q']); // Search TVs for potential alias matches $sql = "SELECT tvc.contentid as id, tvc.value as value FROM " . $modx->getFullTableName('site_tmplvars') . " tv "; $sql .= "INNER JOIN " . $modx->getFullTableName('site_tmplvar_templates') . " tvtpl ON tvtpl.tmplvarid = tv.id "; $sql .= "LEFT JOIN " . $modx->getFullTableName('site_tmplvar_contentvalues') . " tvc ON tvc.tmplvarid = tv.id "; $sql .= "LEFT JOIN " . $modx->getFullTableName('site_content') . " sc ON sc.id = tvc.contentid "; $sql .= "WHERE sc.published = 1 AND tvtpl.templateid = sc.template AND tv.name = '$aliasesTV' AND tvc.value LIKE '%" . $modx->db->escape($documentAlias) . "%'"; $results = $modx->dbQuery($sql); // Attempt to find an exact match $found = 0; while ($found == 0 && $row = $modx->db->getRow($results)) { $pageAliases = explode("\n", $row["value"]); while ($found == 0 && $alias = each($pageAliases)) { if (trim($alias[1]) == $documentAlias) // Check for a match $found = $row["id"]; } } if ($found) // Redirect to new document, if an alias was found { $pageUrl = $modx->makeUrl($found, '', '', "full"); $modx->sendRedirect($pageUrl, 0, "REDIRECT_HEADER", "301"); // Send a permanent redirect exit(0); } header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); }