We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23219
    • 18 Posts
    I made a very easy snippet:
    $url = $modx->makeUrl($id);// page id to redirect to
    $modx->sendRedirect($url, 0, ’REDIRECT_HEADER’, ’301’); // redirect to url with the code 301

    When this snippet is called on a specific page with $id parameter set to target page it works and redirects. But, there is a problem - when looking in Apache logs, it always uses 302 code instead of 301. I also tried with ’301 some text here’ but same result - always 302 redirect. I looked into source code of sendRedirect function and I see no problems there... any ideas?

    Possibly a bug in MODx?
      • 23219
      • 18 Posts
      I think I found the problem - ’301’ is placed directly into header which does not make proper header. I replaced it with:

      $url = $modx->makeUrl($id);// page id to redirect to
      $modx->sendRedirect($url, 0, ’REDIRECT_HEADER’, ’HTTP/1.1 301 Moved Permanently’); // redirect to url with the code 301

      which seems to do the trick. hope this helps someone. I also updated the info on the Wiki hopefully correctly smiley
        • 22303 MODX Staff
        • 10,725 Posts
        Thanks for pointing that out phazze. That probably could use a more abstract way to set those values so it could send HTTP/1.1 or 1.0 appropriately based on the server capabilities, though I’m not sure if that is really an issue for anyone.