Magento – Programmatically Add Entries to URL Rewrite Mgmnt Console

Mage::getModel('core/url_rewrite')
	->setIsSystem(0)
	->setStoreId($storeId)   
	->setOptions('RP') 	
	->setIdPath('index.php?cat=c' . $oscCategoryId . '_' . $this->strip($data['name']) . '.html')
	->setTargetPath($categoryModel->getUrlPath() . '.html')
	->setRequestPath('index.php?cat=c' . $oscCategoryId . '_' . $this->strip($data['name']) . '.html')
	->save();

Posted in Lab | 1 Comment

Oscommerce to Magento Product Import with URL Mapping for SEO

Here is a brief writeup on how to import products and categories from an osCommerce based store and at the same time generate a RewriteMap to map your previous shops URL’s to your new ones using 301 redirects.

Steps are as follows:

Use magento connect manager to install the Oscommerce Import plugin using extension key ‘magento-core/Mage_Oscommerce’.

As of this time, support for Magento 1.4.1.1 requires you to overwrite Run.php in the /magentoroot/app/code/core/Mage/Oscommerce/Block/Adminhtml/Import directory with the following file found here (rename to Run.php) .

Upload and overwrite an updated version of Oscommerce.php to the /magentoroot/app/code/core/Mage/Oscommerce/Model dir. Download copy of this file here.

Take note that there is some code that you will need to update to create the proper markup for the oscommerce url’s from your old store. This will be store specific so what’s included is just a guideline of what needs to be done.

Be aware that this script will create a new Root category and store view under the website you select.

Now import your products and categories by going to System -> Import/Export -> OsCommerce and setting up a profile and then running the profile. More details can be found here.

Mod Rewrite mods are as follows:

The script will use the mapped .txt file created by the importer script. An example of the one that’s created by my import script can be found here.

#place the following in vhost.conf or http.conf
#make sure the following is not inside the <Directory /path/to/dir></Directory> tags
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteMap osccat txt:/var/www/vhosts/rockstarenergyshop.com/subdomains/core/httpdocs/osc-to-magento-cat.txt
    RewriteMap oscprod txt:/var/www/vhosts/rockstarenergyshop.com/subdomains/core/httpdocs/osc-to-magento-prod.txt
</IfModule>


#place the following in the magento .htaccess file right after the #RewriteBase /magento/ line

RewriteCond %{QUERY_STRING}  ^cat=(.*.html).*
RewriteRule ^index.php$ /${osccat:%1}? [R=301,L]
	
RewriteCond %{QUERY_STRING}  ^info=(.*.html).*
RewriteRule ^product_info.php$ /${oscprod:%1}? [R=301,L]

References:

http://www.magentocommerce.com/boards/viewthread/43238/#t156277

http://corz.org/serv/tricks/htaccess2.php

http://www.magentocommerce.com/wiki/import-export_and_data_manipulation/creating_an_oscommerce_import_profile

Posted in Lab | 2 Comments