We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1932
    • 137 Posts
    If it’s already set, why not check it against the 404 id:

    if ($modx->documentIdentifier == $modx->config['error_page'])


    Redirect definitely works from OnWebPageInit since that how it’s done in SEO Strict (which works with RC1).
      • 1209
      • 49 Posts
      Hello again.

      After some additional struggle here is the resume.

      [tt]OnWebPageInit[/tt] event suggested by ApoXX is not fired with 404 case. The [tt]executeParser()[/tt] routes the process to the [tt]sendErrorPage()[/tt] function — 9 lines before [tt]OnWebPageInit[/tt] is fired.

      So we have to fall back to the usage of [tt]OnPageNotFound[/tt] initially hinted by Mark.

      My first plugin was redirecting perfectly, but due to its two step solution, user was first getting the 404 response and then on [tt]error_page[/tt] (id=1 by default) the 301 redirect was happening. That is wrong.

      So I have recoded the plugin and now it clearly sends "HTTP/1.1 301 Moved Permanently" and makes redirect.

      I don’t use [tt]sendRedirect(...)[/tt] consciously, because that function goes to [tt]postProcess()[/tt] after sending headers and we end up with id=1 again. I use raw php [tt]header(...)[/tt] function.

      To prevent return to [tt]sendErrorPage()[/tt] after the OnPageNotFound event invokation (which would bring us to id=1 again), I had to put [tt]break[/tt] command.

      $TVname = 'oldURI';
      
      $current = $_SERVER["REQUEST_URI"];
      $tmplvars = $modx->getFullTableName("site_tmplvars");
      $contentvalues = $modx->getFullTableName("site_tmplvar_contentvalues");
      $docQuery = $modx->db->query("SELECT contentid FROM $tmplvars INNER JOIN $contentvalues ON $tmplvars.id = $contentvalues.tmplvarid WHERE $tmplvars.name = '$TVname' AND $contentvalues.value = '$current'");
      if ($modx->db->getRecordCount($docQuery) > 0) {
        $docRow = $modx->db->getRow($docQuery);
        $id = $docRow['contentid'];
        $url = $modx->makeUrl($id, '', '', 'full');
        header("HTTP/1.1 301 Moved Permanently");
        header("Location: $url");
        break; 
      }
      
        • 21954
        • 3 Posts
        This looks like it would almost do what I need to do - we’re converting a site from a .NET based site to Modx. The issue for us is that the old site has a lot of pages, so entering the entire URI of the old pages from the old site would take some time.
        The old pages have the format www.domain.dom/Default.aspx?pageid=21

        What we have done is add a template variable to the new Modx pages recording the old "pageid" value. So if I can strip the pageid querystring parameter from the incoming URI, I could use this same technique to handle the redirect to the new Modx pages. Question is, how do I pull that querystring parameter from the incoming URI? I’m no PHP expert, but I assume there’s probably a function call in PHP to access querystring parameters?

        Any help would be MUCH appreciated

        Thanks,

        Mark E
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: NZMarke at Aug 08, 2007, 07:19 AM
          I’m no PHP expert, but I assume there’s probably a function call in PHP to access querystring parameters?
          $_GET[’pageid’]

          This discussion is closed to further replies. Keep calm and carry on.