Magento Forum

URL Rewriting
 
Andre
Member
 
Total Posts:  55
Joined:  2007-08-31
Mongolia
 

The url’s that are re-written are massively long. is there an easy way to reduce these down?

example: catalog/category/view/s/surf/id/29/

that should be easily narrowed down to /surf/

can anyone provide a rewrite rule that will effectively work in this manner?

Cheers
André

 
Magento Community Magento Community
Magento Community
Magento Community
 
howellnick
Jr. Member
 
Avatar
Total Posts:  13
Joined:  2007-08-31
 

In short to answer your question, yes there is a way to do this.

But first I will ask, are you familiar with Zend Framework and MVC (Model-View-Controller)? 

If not, here is what is happening (note: I have only briefly looked at Magento’s source but this is from my experience with Zend Framework):
example: catalog/category/view/s/surf/id/29/
Every page request is redirected to “index.php” and then the Zend Framework breaks down the URI_REQUEST from there:
module: “catalog”
controller: “category”
action: “view”
Everything after that point is defining a parameter (or in many applications this would be the query string which you may be familiar with. In this instance it would look like this: “?s=surf&id;=29") However, for search engine optimization purposes, Zend Framework puts the query parameters in the URL to look like a directory tree.

So, I would like to know why you think these are “long” URL’s.  In my opinion, these describe what page the user is requesting very well and therefore they can anticipate what content they are going to get before they load the page. They are rather concise compared to many URL’s I see nowadays. But if it is really a big issue to you you can define custom routes in Zend Framework to do what you are asking.

Something like this for this scenario (again, not tested this in Magento but as long as they are using the traditional Module Rewrite this should be about right):

$route = new Zend_Controller_Router_Route(
    
'surf',
    array(
        
'module' => 'catalog',
        
'controller' => 'category',
        
'action' => 'view',
        
's' => 'surf',
        
'id => '29'
    )
);

$router->addRoute('
surf', $route);

Please don’t come murder me if that code doesn’t exactly work. That was off the top of my head wink (It more than likely won’t work, it should give you an idea of what to do I hope.)
(more here: http://framework.zend.com/manual/en/zend.controller.router.html)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Johan
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2007-09-01
Sweden
 
FrenchToast - 04 September 2007 11:05 AM

So, I would like to know why you think these are “long” URL’s.

http://demo.magentocommerce.com/catalog/product/view/s/sony-vaio-vgn-txn27n-b-11-1-notebook-pc-intel-core-solo-processor-u1500-2-gb-ram-100-gb-hard-drive-dvd-rw-drive-vista-business-charcoal-black/id/27/category/15/

Think? :D

I summed up the issue here:

http://www.magentocommerce.com/boards/viewthread/147/

 
Magento Community Magento Community
Magento Community
Magento Community
 
howellnick
Jr. Member
 
Avatar
Total Posts:  13
Joined:  2007-08-31
 
Johan - 04 September 2007 11:21 AM

http://demo.magentocommerce.com/catalog/product/view/s/sony-vaio-vgn-txn27n-b-11-1-notebook-pc-intel-core-solo-processor-u1500-2-gb-ram-100-gb-hard-drive-dvd-rw-drive-vista-business-charcoal-black/id/27/category/15/
Think? :D

Heh.
Well I do agree with you there. That one is a bit long, but I do think the “sony-vaio-vgn-txn27n-b-11-1-notebook-pc-intel-core-solo-processor-u1500-2-gb-ram-100-gb-hard-drive-dvd-rw-drive-vista-business-charcoal-black” was on purpose to show that you “can” (not to mean you should, but that is up to the store owner) have long product names in the URL.

Take for instance (a more reasonable demo url):

http://demo.magentocommerce.com/catalog/product/view/s/acer-ferrari-3200-notebook-computer-pc/id/26/category/15/
I would like to see it look like this:
http://demo.magentocommerce.com/catalog/product/view/acer-ferrari-3200-notebook-computer-pc
This reduces the depth of the “directories” to 4. If there are identical product names simply append a number to the URL (...computer-pc-2) The “/id/26/category/15/” on the end seems rather silly as it should be able to be determined server side.
You could even do more routing and remove the “view” part but that is trivial. But then again, I like to be able to see what module, controller, and action I am looking at. This also helps developers and template designers find the files that they want to change.
 
Magento Community Magento Community
Magento Community
Magento Community
 
Johan
Sr. Member
 
Avatar
Total Posts:  104
Joined:  2007-09-01
Sweden
 

The problem still persists that search engines count those as directories and wont go as deep as you would like on your site, unless you have a lot of trust and content.

Stripping out the “catalog/product/view/” part would help you more in the rankings than leaving them in, since it both shortens the url and has less directories in the tree.

I’ll continue the discussion in the other thread instead of splitting them up.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top