One of the things you have to deal with when switching from another e-commerce software to Magento are URL redirects. Over the past years you (hopefully) received many incoming deep links. You surely know that incoming links are one of the main ranking factors for most search engines. So when you switch to another e-commerce software, these deep links get useless because they point to subpages that don’t exist (unless you don’t have the exact same URL structure in your new shop). The common way to solve this issue is just to do a 301 redirect (permantly redirect) from the old URLs to the new ones. You have the possibility to define the redirects in your .htaccess file or with the Magentos build-in “URL Rewrite Management” (in the Backend “Catalog” -> “URL Rewrite Management”).
However, both of these methods have some disadvantages. The .htaccess file could be overwritten when you update Magento. Also if you change the URL structure inside Magento you’ll have to update the .htaccess file each time. The Magento build-in Tool is nice if you only have to do a couple of rewrites. But let’s say you have 2000 or more redirects you want to define… you can take a week off, because you have to define each redirect manually.
I decided to write a small extension to give you an alternative way of defining redirects. Just named it “Massredirect”. You can download it here. For installation just copy it into your Magento main folder and run the command “tar -xvf massredirect.tar”. This will extract the extension files to the desired places. Before you start defining the redirects, make sure you got rid of the cache and the extension shows up in the advanced tab of the configuration site. To define the redirects open the CSV file “redirects.csv” located in the folder “/app/code/local/Velite/Massredirect/etc/” in a text editor. Each row in the CSV defines a redirect. Basically there are two possibilties of defining a redirect:
Possbility 1:
old-URL;type;entity_id;website_id;store_id
for example:
www.myshop.com/product.php?productid=123;product;5;1;1
This will redirect a user typing the URL “www.myshop.com/product.php?productid=123″ to the product page of the product with the ID 5 on the default website and store. Notice that the URL must be specified without “http://”. “type” can either be “product” or “category”.
Possbility 2:
old-URL;new-URL
for example:
www.myshop.com/product.php?productid=123;www.myshop.com/my-nice-product.html
Keep in mind that the second possbility has the same disadvantage like defining the redirects in the .htaccess file. This means, if you change the URL structure inside of Magento you will also have to update the CSV. However, you can mix both possibilities in the CSV file.
So how does this extension work?
Basically the preDispatch method of the Mage_Core_Controller_Varien_Action gets observed (the event is named “controller_action_predispatch”). If the requested action is “noRoute”, the CSV gets parsed and looked up if there is a mapping available for the typed-in URL. In that case the user (or the bot) gets redirected to the new URL (with a Status 301-Redirect).
Feel free to make any further suggestions.



It works, which is amazing because I cant for the life of me figure out how to do so with magento’s built in device.
I cant seem to find it in the admin panel tho, even though it works. No big issue I suppose, unless there is important things within the admin panel that need setting?
Probable noobie question but how do you run the command: tar -xvf massredirect.tar?
Hi,
It would be great to publish this extension of magento connect no ?
@ Remco
You have to logon youre Server via SSH to run that command.
@zmove
We will think about it :)
- Simon
Simon – this is brilliant! I real life-saver for us as we work to transition our site over to Magento. 40,000 plus links to enter through the Magneto admin wasn’t an option for us. Thanks for sharing this with the community.
Thank you for this no-nonsense module. I simply couldn’t get the embedded magento url rewrite to work. Your’s worked perfectly–the first time!
Another big thank-you for this really straightforward example. I was trying to figure out how to create a simple a url redirect module based on IP, and this got me pointed in the right direction!
Great job. We used the method #2 above where:
http://www.myshop.com/product.php?productid=123;www.myshop.com/my-nice-product.html
I found that if we did not provide a redirect we got a standard magento error page. Not very helpful to the customer. Since this was the only format that I knew we would use, I modified the /Model/Redirector.php so that it looked like this:
getRequest();
$actionName = $request->getActionName();
$requestUrl = $request->getHttpHost() . $request->getRequestUri();
if ($actionName == ‘noRoute’) {
$mappings = file(Mage::getModuleDir(‘etc’,
‘Velite_Massredirect’).’/redirects.csv’);
foreach ($mappings AS $mapping) {
$pieces = explode(‘;’,$mapping);
$sourceUrl = trim($pieces[0]);
if (count($pieces) == 2) {
$destinationUrl = ‘http://’ . trim($pieces[1]);
if ($sourceUrl == $requestUrl) {
$response = Mage::app()->getResponse();
$response->setRedirect($destinationUrl, 301);
$response->sendResponse();
exit;
}else{
if ($sourceUrl == $requestUrl) {
$response = Mage::app()->getResponse();
$response->setRedirect($destinationUrl, 404);
$response->sendResponse();
exit;
}
}
}
}
}
}
public function getProductUrl($entityId, $websiteId, $storeId) {
Mage::app()->getWebsite()->setId($websiteId);
Mage::app()->getStore()->setId($storeId);
$product = new Mage_Catalog_Model_Product();
$product->load($entityId);
return $product->getUrlPath();
}
public function getCategoryUrl($entityId, $websiteId, $storeId) {
Mage::app()->getWebsite()->setId($websiteId);
Mage::app()->getStore()->setId($storeId);
$category = new Mage_Catalog_Model_Category();
$category->load($entityId);
return $category->getUrlPath();
}
}
If using Yoast SEO optimizer extension with velite. It crashes system.
Works like a dream! Brilliant stuff…. now I’ve just got to map all my old URL’s to the new ones now.
But, this tool makes it all so much easier – Many thanks again!
John
Absolutely awesome. This should be part of the magento core!
Got it working finally. If you’re having trouble, make sure you’re using a semicolon and also omit the protocol (“http://”).
Is it possible to point from one store to another store on the same site? For example:
http://www.example.com/store_one/redirect_from.html
http://www.example.com/store_two/redirect_to.html
All of our redirects to one store from another are not working and I was wondering if anyone found a fix to this.
Hi i tried using method 2 but when i add more than 1 redirect it stops working, could you tell me what can be the problem? by the way am using Magento ver. 1.4.1.1
Thanks for this it works perfectly, even in 1.4.1.1
Just wanted to say thanks for this helpful, module!
I had to make a tiny modification to get it to work for me since my old store lived in a sub-folder on the server, and my magento lives at document root:
Simply added a forward slash to the computed “destination” url to make it relative to server root.
in Velite/Massredirect/Model/Redirector at line 42 I added the following line:
$destinationUrl = ‘/’ . $destinationUrl;
Thanks again for sharing your extension.
Can someone please help me. The redirect for me takes me to the 404 page. Have a look at the following values that are just echoed right before the redirect code
sourceUrl: localhost/www/mysite/catalog/category/view/id/14?and_series=632
requestUrl: localhost/www/mysite/catalog/category/view/id/14?and_series=632
destinationUrl: http://localhost/www/mysite/my-static-page.html
inside if $sourceUrl == $requestUrl
What *should* happen is that url in the browser should read “http://localhost/www/mysite/my-static-page.html” whereas the content should remain the same. Instead the browser does show the url “http://localhost/www/mysite/my-static-page.html” but I also get a 404 error.
I’m in dire need for some guidance here to resolve this issue. Please help. Thank you all.
This is great. Thanks for saving me a ton of time.
Does the module currently support wildcards? Our old URL structure had the products id followed by whichever method was used to reach it. So, I would like to do something like http://www.myshop.com/product.php?product_id=123&;*;
Thanks again!
Like Jeff, i a wonder if we can use wildcards.
I have waaaaay to many products on the old site to make a line for each.
I’m also looking for a wild card option. My URLs can be displayed many different ways for a single product on my old website, and a wildcard option would be extremely helpful.
I must say that this extension was an absolute life saver after I couldn’t get regular 301 redirects working using the standard htaccess method.
Great work, and thank you for this!
Yes the post is really great opening the eyes and minds while helped gaining knowledge that how companies utilize the social meida’s and using them for making their outlets.
Amazingly insightful article. If only it was as easy to implement some of the solutions as it was to read and nod my head at each of your points :P
You should really clean out the spam here, update this extension’s compatibility, add wildcards and keywords, and start selling it. I would buy it if you add the wildcards and keywords.
This is great! I was dreading spending a few hours entering several hundred rewrites by hand, but then I found this and instead it took me all of five minutes.
Just wanted to say thanks!
I will check it out this module of redirect for Magento. I also use Yoast for that.
Anyone tested it with Yoast_CanonicalUrl, Yoast_MetaRobots (maybe Ron ? is it working for you now ?) and Mageworx SEO Suite ? ? Does it works ?
Can anyone confirm that this still works with latest magento v1.5 stable version?
Thanks, John
I’ve set this up correctly but i’m just getting 404 errors. I’ve checked everything and it seems to be set up correctly.
Has anybody else had the same problem?
doesnt work when using magento compiler 1.4.01
warning include(velite…redirector.php) failed to open stream : No such file for directory in ..includes.src/Varian_Autoload.php
Not working on v1.5.1. If anyone fixes please post how.
Same as Jeff !
Does anybody has a solution ?
You could certainly see your skills in the paintings you write. The sector hopes for more passionate writers such as you who arent afraid to mention how they believe. Always follow your heart.
I truly recognize that which you web site in right here, really insightful and smart. One issue, Now i am operating Opera in Linux system and some of the content are just a little wonky. I understand its not a popular, but its nonetheless something to watch out for. Just giving you a heads up.
This is my first time i visit here. I discovered lots of useful thing in your weblog especially its discussion. On the numerous feedback on your posts, I guess Im not the only one having all the enjoyment right here! keep up your great work.
Your post is simply spectacular and I can assume you are an expert on this field. Thanks a million and please keep up the fabulous work. Thanks a lot once again.
Your website is so cool. I am impressed by the info that you have on this site. It reveals how nicely you understand this subject.