1

I have made the following changes:

1) System > Configuration > Web > “Use Web Server Rewrites” to Yes

2) System > Configuration > Catalog > “Use Categories Path for Product URLs” to YES

3) System > Configuration > Catalog > “Use Canonical Link Meta Tag For Categories” to Yes

4) System > Web > Search Engine Optimization -> Use Web Server Rewrites to Yes

5) System > Catalog -> Search Engine optimizations -> Use Categories Path for Product URLs -> to NO

Now I have the situation, when i click on product a get the following friendly url: www.domain.com/name-of-the-product, which is what I want to archive.

Also I use the following code on my view page to display related products from same category.

<!--Related products-->
    <?php $categories = $_product->getCategoryIds(); ?> 
    <?php $result = array(); 
    foreach($categories as $cat_id) { 
    $category = Mage::getModel('catalog/category'); 
    $category->load($cat_id); 
    $collection = $category->getProductCollection();
    foreach ($collection as $product) { 
    $result[] = $product->getId(); 
    } 
    } 
    ?> 
<div class="related-prod-conteiner"> 
    <ul class="r-prod-list-horizontal"> 
        <?php if(sizeof($result) >= 5) 
        { 
        $ourneed = array_rand($result,5); 
        foreach($ourneed as $cc) 
        { 
        $thisproduct= Mage::getModel('catalog/product')->load($result[$cc]); 
        ?> 
            <li> 
                <div class="item-content-image">
                    <a href="<?php echo $thisproduct->getProductUrl()?>"><img class="thumbnail" src="<?php echo Mage::helper('catalog/image')->init($thisproduct, 'thumbnail')->resize(150, 150)?>" alt="<?php echo $thisproduct->getName()?>"></a>
                </div>
                <div class="item-content-name"> 
                    <a href="<?php echo $thisproduct->getProductUrl()?>">
                    <h2 class="product-name">
                        <div class="three-dots-3">
                            <span class='ellipsis_text'><?php echo $thisproduct->getName()?></span>
                        </div>
                    </h2>
                    </a>
                </div>
                <div class="item-content-price"> 
                    <?php
                    $product_block = new Mage_Catalog_Block_Product;
                    echo $product_block->getPriceHtml($thisproduct);
                    unset($product_block)
                    ?>
                </div>
                <div class="item-content-rate">
                    <?php echo $this->_reviewsHelperBlock->getSummaryHtml($thisproduct, short); ?>
                </div>
            </li> 
        <?php } ?> 
        <?php }else { 
        foreach($result as $cc) 
        { 
        $thisproduct= Mage::getModel('catalog/product')->load($cc); 
        ?> 
        <li> 
        <a href="<?php echo $thisproduct->getProductUrl(); ?>" title="<?php echo $thisproduct->getName(); ?>" ><img src="<?php echo $this->helper('catalog/image')->init($thisproduct, 'small_image')->resize(200) ?>" width="200" height="200" alt="<?php echo $thisproduct->getName(); ?>" /></a> </li> 
        <?php } 
        } 
        ?> 
    </ul> 
</div>
    <!--/Related products-->

Above code works just fine, but when I click on the product which is displayed by above code, a I'm getting the following link: www.domain.com/catalog/product/view/id/234/s/name-of-the-product

I would like to display it as www.domain.com/name-of-the-product

thanks

2

I assumed this could be the reason of the get productUrl and i found the solution, which is:

instead of getProductUrl use getUrlPath()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.