Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Multiple Product URLS - SOLVED
 
seoguy
Member
 
Total Posts:  46
Joined:  2008-01-25
 

Hey all,

There has been some discussions on how to have just 1 product url regardless of the subcategories you place that product in.

The problem: 

When setting up your categories what happens is that the category you create name is appened to the product url thus causing multiple urls to the same product:

Let’s say you have product a and you place that in Cat 1, cat 2, cat 3.

what you end up with is actually 4 seperate urls to that product:
http://www.url.com/producta.html <-- seen in autogenerated product site map
http://www.url.com/cat1/producta.html
http://www.url.com/cat2/producta.html
http://www.url.com/cat3/producta.html

This is created by the way you set up your categories.  The tree structure in your manage categories will look like this:

Default Category
- Cat1
- Cat2
- Cat 3

I should note that is the way must people are recommending on this board, and in fact may be required if you want your products to appear using the store’s category pages.

The solution:

1.  Create all your categories equal to the default category.  The category tree structure will look like this:

Default Category
Cat1
Cat2
Cat3

2. Create a new cms page for Cat1, another for Cat2 and another for cat3.

On those newly created cms pages, place this code:

{{block type="catalog/product_list" category_id="2" template="catalog/product/list.phtml"}}

***Please note:  category_id="2" is the default category number that contains every product in your store (great for a View All cms page); thus replace the number 2 with the category number of the category you want to display.

How Magento creates category numbers:  they are created sequentially as you add categories.  Thus in a new install “default category” is category 2.  In this example, cat1, the first created by me, would be category number 3, cat2, the second created would be category number 4, etc....  I am not sure where you can determine these without keep track as you create because they wont show up in the URL rewrite management.  You probably could see them in your database.

Thus on the cms page for cat1 you would place this code:

{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}

What results in doing this is that you could place product a in all three cats, but product a will only have 1 url: http://www.url.com/producta.html

My settings (I do not know if relevant or not):

‘Use category path in product url’ = No
All categories that were created are diabled, since I am accessing the category via the code on the cms page.

You will also need to create a menu to access the cms pages.

To see and example, see my very young, under development site:  [url=http://www.justfavorsdirect.com]http://www.justfavorsdirect.com[/url]

I have no idea if this works via a layered nav environment, I do not use it.

Hope this helps some.

Chris

 
Magento Community Magento Community
Magento Community
Magento Community
 
golles
Sr. Member
 
Total Posts:  257
Joined:  2008-01-15
 

as per other thread - this is good but in no way solves the issues and is also not a great long term solution (but a very creative workaround) - we need to expect category pages to be generated when we create categories in my view and not set up a new cms page for each one.

also it resolves just the ‘product in duplicate categories’ issue

there are also urls created for every category view, product view etc so there are 10’s of urls being generated for each product and each category, especially if that product has different attributes.

your solution is a good one for the ‘product in duplicate categories’ issue and is very creative but........

but i would not say by a long way this is solved.

 
Magento Community Magento Community
Magento Community
Magento Community
 
warren
Member
 
Total Posts:  67
Joined:  2007-12-18
 

I agree, this is not a solution.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sszettella
Jr. Member
 
Total Posts:  5
Joined:  2008-04-28
 

This may or may not help anyone, but I have a site to launch and having many URLs pointing to the same product is not an acceptable solution to me.

Here is what I’ve found:

code/core/Mage/Catalog/Model/Product/Url.php

If you look at the function getProductUrl, it can be modified to unconditionally return a single URL for a product, no matter where it appears, as configured by the admin.  Here is the code for my modified function:

public function getProductUrl($product)
    
{
        
//SAS Hack to produce one and only one URL for a product
        
Varien_Profiler::start('REWRITE: '.__METHOD__);
        
$rewrite $this->getUrlRewrite();
        if (
$product->getStoreId()) {
            $rewrite
->setStoreId($product->getStoreId());
        
}
        $idPath 
'product/'.$product->getId();

        if (
$product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
            $idPath 
.= '/'.$product->getCategoryId();
        
}

        $rewrite
->loadByIdPath($idPath);

        if (
$rewrite->getId()) {
            $url 
$this->getUrlInstance()->getBaseUrl().$rewrite->getRequestPath();
        
Varien_Profiler::stop('REWRITE: '.__METHOD__);
        
}
        
return $url;
}

I don’t completely understand all of the inner workings, however my testing indicates that this shows the product URL the same in all of the contexts I have been able to locate.  Included are the product grid, recently viewed, shopping cart, category pages, and search results so far have tested positive.

With this modification, the URL no longer includes the category (and can not by definition)

While I don’t think it’s the best solution, I hope someone finds this useful.

Also, I should note that I have set “Use categories path for product URLs” to NO and “Use Web Server Rewrites” to YES.

 
Magento Community Magento Community
Magento Community
Magento Community
 
FatDan
Jr. Member
 
Total Posts:  14
Joined:  2008-04-29
 

That’s a neat solution and it seems to work great.

What do the team members think about this fix?

 
Magento Community Magento Community
Magento Community
Magento Community
 
FatDan
Jr. Member
 
Total Posts:  14
Joined:  2008-04-29
 

When you add a product to compare it produces this url

http://www.domain.com/catalog/product/view/id/7/

Instead of http://www.domain.com/voodoo-knife-block.html

Not sure if this is important but it would be nice to solve this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sander
Sr. Member
 
Avatar
Total Posts:  232
Joined:  2008-01-08
Netherlands
 
FatDan - 26 May 2008 04:12 AM

That’s a neat solution and it seems to work great.

What do the team members think about this fix?

Wondering about that too. Currently, with a selection of wines, these urls are pointing to the same wine:

store/chateau-roquefort-2006.html
store/chateau-roquefort-2007.html

Both point to chateau-roquefort-2006. Not what we want of course smile

The above fix would be fine, but we’d also like to know what the core team thinks of it. Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sander
Sr. Member
 
Avatar
Total Posts:  232
Joined:  2008-01-08
Netherlands
 
sszettella - 12 May 2008 05:48 PM


With this modification, the URL no longer includes the category (and can not by definition)

While I don’t think it’s the best solution, I hope someone finds this useful.

Also, I should note that I have set “Use categories path for product URLs” to NO and “Use Web Server Rewrites” to YES.

Nice quick fix, but it breaks the breadcrumbs. Oh well, time to decide what’s more important, SEO or detailed breadcrumbs. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
lazzymonk
Guru
 
Avatar
Total Posts:  391
Joined:  2008-04-03
England
 

doesnt the “Use categories path for product URLs” option in system-configuration-catalog-Search Engine Optimizations part of the admin section do this anyway?

 
Magento Community Magento Community
Magento Community
Magento Community
 
golles
Sr. Member
 
Total Posts:  257
Joined:  2008-01-15
 
lazzymonk - 12 June 2008 04:52 PM

doesnt the “Use categories path for product URLs” option in system-configuration-catalog-Search Engine Optimizations part of the admin section do this anyway?

no

basically if a product is in more than 1 category it will add a -1.html to the end of the product url in the second category, -2.html to the end of the product url in the 3rd category and so on.

also there are multiples views available which generate a unique url again for each product.

the admin section you describe just turns on or off the feature for displaying category names in the the product url - e.g. http://www.example.com/category1/product1.html or http://www.example.com/product1.html - this can be helpful (i.e. turning category names off) but it does not solve all of the url issues that currently exist with magento especially the seperate urls for the same product that exists in multiple categories.

There are numerous issues around the multiple urls, views etc which have not been resolved completely as yet - there are some helpful suggestions to limit the issue, but not a complete solution.  - see seo section.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Sander
Sr. Member
 
Avatar
Total Posts:  232
Joined:  2008-01-08
Netherlands
 
golles - 12 June 2008 10:54 PM

lazzymonk - 12 June 2008 04:52 PM
doesnt the “Use categories path for product URLs” option in system-configuration-catalog-Search Engine Optimizations part of the admin section do this anyway?

basically if a product is in more than 1 category it will add a -1.html to the end of the product url in the second category, -2.html to the end of the product url in the 3rd category and so on.

Additionally, if your product name ends with a number, that number is increased by 1 instead of Magento adding -1 to the url.

 
Magento Community Magento Community
Magento Community
Magento Community
 
allianceetrading
Jr. Member
 
Total Posts:  13
Joined:  2009-09-27
 

Anyone find a solution? This is problem is driving me crazy.

 
Magento Community Magento Community
Magento Community
Magento Community
 
otzstzzn
Mentor
 
Total Posts:  1071
Joined:  2009-07-13
 

Hi,

any news here ??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Magento Support Service
Jr. Member
 
Total Posts:  13
Joined:  2010-11-07
 

We have been battling with this for a long time, there is basically no simple solution. Set the site to not use categories in urls and your seo becomes a problem, keep them there and duplicate content occurs. This is really something that should be resolved in the core as everyone is struggling with it, the getProductUrl solution looks like a good workaround.

This is another solution here:
http://www.magentocommerce.com/boards/viewthread/41386/

MagSupportNet

 
Magento Community Magento Community
Magento Community
Magento Community
 
privera
Jr. Member
 
Total Posts:  2
Joined:  2012-12-03
 

Easy to fix..

System->Configuration->Catalog->Search Engine Optimization

Look for the option Use Categories Path for Product URLs and choose no!

Magento will only generate one URL for the product!! Remember to re index

 
Magento Community Magento Community
Magento Community
Magento Community
 
PowercutUK
Member
 
Avatar
Total Posts:  65
Joined:  2011-04-04
Carmarthen, Wales, UK
 
Sander - 12 June 2008 12:39 PM

sszettella - 12 May 2008 05:48 PM


With this modification, the URL no longer includes the category (and can not by definition)

While I don’t think it’s the best solution, I hope someone finds this useful.

Also, I should note that I have set “Use categories path for product URLs” to NO and “Use Web Server Rewrites” to YES.

Nice quick fix, but it breaks the breadcrumbs. Oh well, time to decide what’s more important, SEO or detailed breadcrumbs. smile

This seemed to sort it for me. Hope it helps:

public function getProductUrl($product$useSid null)
    
{
           
if ($useSid === null{
            $useSid 
Mage::app()->getUseSessionInUrl();
        
}

        $params 
= array();
        if (!
$useSid{
            $params[
'_nosid'true;
        
}
        
//SAS Hack to produce one and only one URL for a product
        
Varien_Profiler::start('REWRITE: '.__METHOD__);
        
$rewrite $this->getUrlRewrite();
        if (
$product->getStoreId()) {
            $rewrite
->setStoreId($product->getStoreId());
        
}
        $idPath 
'product/'.$product->getId();

        if (
$product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
            $idPath 
.= '/'.$product->getCategoryId();
        
}

        $rewrite
->loadByIdPath($idPath);

        if (
$rewrite->getId()) {
            $url 
$this->getUrlInstance()->getBaseUrl().$rewrite->getRequestPath();
        
Varien_Profiler::stop('REWRITE: '.__METHOD__);
        
}
        
return $url;
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2