We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24007
    • 38 Posts
    I'm trying to redirect an old page to a new page using the redirector plugin

    old-info-page

    new-info-page

    At this time any incorrect urls entered into the browser are redirecting to the 'new-info-page'

    e.g. http://www.mywebsite.com/somerandomgibberish -- >> new-info-page
    just want gibberish to be redirected to home page (resource ID1 as in systems settings error page)

    Logically I suspect I need an exclusive regex expression to look for an exact match of 'old-info-page'

    Phone numbers and email addresses are about my limit at present for regex, please can someone familiar with regex help.

    Many thanks

    Jay
      • 47401
      • 295 Posts
      i would use the .htaccess file to do a 301 redirect, no need to complicate things smiley

      add a line:

      Redirect 301 http://www.domain.com/old-web-page http://www.domain.com/new-web-page

      save the file and try to visit the old web page, you should be re directed to the new web page.
        • 47401
        • 295 Posts
        no need to use regex, you could check the domain url, and if the url matches old-page, then redirect to new page.

        create a snippet and call it before the header.
        <?php
        $Get_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URl'];
        if($Get_url == "http://www.domain.com/old-page") {
        
        $url = $modx->makeUrl(54); // the new page ID goes in here
        $modx->sendRedirect($url);
        
        }
        
        ?>
        
        
          • 3749
          • 24,544 Posts
          This is the recommended method for makeUrl(), though doing it in .htaccess will be faster and more efficient:

          $url = $modx->makeUrl(54, "", "", "full"); // the new page ID goes in here
          $modx->sendRedirect($url);
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 24007
            • 38 Posts
            I'd ended up using the .htaccess method a few days since, already use is for non www. to www domain, just wanted to make the redirector method work though as it may come in useful in the future.

            Thanks for the replies, will attempt research and understand regex syntax and structure.

            -----------------------------------------------------------------------------------------------------------------

            I'm currently lamenting over my decision to migrate to a .com from a .co.uk, even though 301 in place and webmaster tools has been notified of domain move. Definite drop in SERP. :'(