We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered custom SEO url

    • 42433
    • 1 Posts
    Hello, in my project i will need to use
    redirect fake pages (SEO url to one page with snippet, wich takes parametrs from url and print custom product page)
    sale-product-99.html to index.php?id=35
    sale-product-100.html to index.php?id=35
    sale-product-101.html to index.php?id=35
    How to create diffrerent aliases to one page with snippet?

    in .htaccess i'd wrote such line:

    ^.*sale-product-([0-9]*)\.html$ index.php?id=35 [L]

    In system configuration i also need to use friendly url option.

    When i try to access to sale-product-99.html modx instead of open index.php?id=35 redirect me to product.html page (product.html is a alias of index.php?id=35), also i notice that first it redirect to index.php?id=35 and then again from index.php?id=35 to alias product.html

    Main problem is that i can not specify on which page i can use dynamic url index.php?id=35 and on which use friendly url.
    In revo if i try to setup in page parametrs alias to index.php?id=35 it begins to error (cycle redirection).

    In modx evo i dont have this problem-because i can access to tha same page as product.html and as index.php?id=35 without redirection to friendly url.
    EVO http://infanta.dp.ua/-categ-44-tovar-817.html
    http://infanta.dp.ua/-categ-44-tovar-818.html
    it's all normally redirected to index.php?id=63 page
    and browser and sarch engenies see this page with custom friendly url.



    Sorry for my english. Thanks for any help.


    UPD
    comment line #100 in core/model/modx/modrequest.class.php
    //$this->modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));

    it's seems working properly now. any ideas with possible problems this "modification"? security e.t.c


    This question has been answered by markh. See the first response.

    [ed. note: madmaximus85 last edited this post 13 years, 8 months ago.]
    • discuss.answer
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      Uncomment that line again and disable the request_method_strict setting via System > System Settings; that should do the trick as well.

      Instead of the htaccess rewrite, I personally prefer using a plugin triggering on OnPageNotFound, something like this:

      <?php
      $search = $_SERVER['REQUEST_URI'];
      $base_url = $modx->getOption('base_url');
      if ($base_url != '/') {
          $search = str_replace($base_url,'',$search);
      }
      $search = trim($search, '/');
      
      $searchExploded = explode('.', $search);
      $matchPrefix = 'sale-product-';
      $target = 35;
      
      if (substr($search[0], 0, strlen($matchPrefix)) == $matchPrefix) {
        $product = (int)substr($search[0], strlen($matchPrefix));
        if (is_numeric($product)) {
          $_REQUEST['product'] = $product;
          $modx->setPlaceholder('product', $product);
          $modx->sendForward($target);
        }
      }


      And then you can either look at at the $_REQUEST variable in a snippet, or use the [[!+product]] placeholder.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.