User Tools

  • (Use the same account as the official website)

Site Tools


redirect_links_from_another_platform

Redirect Links From Another Platform

Assuming you have migrated your products to LiteCart from another platform assigning the same IDs. Here are some good mod_rewrite rules for telling Google and others your pages have moved.

Using .htaccess

OpenCart

/.htaccess
  # Redirect old OpenCart URLs
  RewriteCond %{QUERY_STRING} route=product/category
  RewriteCond %{QUERY_STRING} path=([0-9]+_)?([0-9]+)
  RewriteRule ^index\.php$ /index.php/category?category_id=%2 [R=301,L]
 
  RewriteCond %{QUERY_STRING} route=product/manufacturer/info
  RewriteCond %{QUERY_STRING} manufacturer_id=([0-9]+)
  RewriteRule ^index\.php$ /index.php/manufacturer?manufacturer_id=%1 [R=301,L]
 
  RewriteCond %{QUERY_STRING} route=product/product
  RewriteCond %{QUERY_STRING} product_id=([0-9]+)
  RewriteRule ^index\.php$ /index.php/product?product_id=%1 [R=301,L]

osCommerce

/.htaccess
  # Redirect old osCommerce URLs
  RewriteCond %{REQUEST_URI} ^(/|/index.php) [NC]
  RewriteCond %{QUERY_STRING} cPath=([0-9]+)
  RewriteRule .* /index.php/category?category_id=%1 [R=301,L]
  RewriteRule ^.*-c-([0-9]+)\.html$ /index.php/category?category_id=$1 [R=301,L]
 
  RewriteCond %{REQUEST_URI} ^(/|/index.php) [NC]
  RewriteCond %{QUERY_STRING} manufacturers_id=([0-9]+)
  RewriteRule (.*) /index.php/manufacturer?manufacturer_id=%1 [R=301,L]
  RewriteRule ^.*-m-([0-9]+)\.html$ /index.php/manufacturer?manufacturer_id=$1 [R=301,L]
 
  RewriteCond %{REQUEST_URI} ^/product_info.php [NC]
  RewriteCond %{QUERY_STRING} products_id=([0-9]+)
  RewriteRule (.*) /index.php/product?product_id=%1 [R=301,L]
  RewriteRule ^.*-p-([0-9]+)\.html$ /index.php/product?product_id=$1 [R=301,L]

Be sure to add the rules before:

  # No logic for physical files
  RewriteCond %{REQUEST_FILENAME} -d [or]
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^ - [L]

Using The Routing Modules

LiteCart can also resolve external URLs stated using the URL routing modules. Just append the result of the routes() method with more rules. Experimenting with URL parameters is not recommended.

includes/routes/url_category.inc.php
    function routes() {
      return array(
        array( // LiteCart
          'pattern' => '#^.*-c-([0-9]+)/?$#',
          'page' => 'category',
          'params' => 'category_id=$1',
        ),
        array( // osCommerce
          'pattern' => '#^.*-c-([0-9]+)\.html$#',
          'page' => 'category',
          'params' => 'category_id=$1',
        ),
      );
    }
redirect_links_from_another_platform.txt · Last modified: 2020/08/17 11:08 by A User Not Logged in