I have a template file that 'gets' the product url so that I can produce a link to the product. However, the url called is not the SEO friendly version. Can anyone suggest an edit to the code below so that I can get the preferred SEO friendly URL instead?

Current URL


Preferred SEO Friendly URL


PHTML - My Current Code

<?php $product = $categoryProducts->getFirstItem();?>
 <a href="<?php echo $product->getProductUrl()?>">Product Link</a>
<?php endif;?>

As per as your code,you have tried to get product($product) 's Seo Url from a product collection ($categoryProducts).

In order to get seo url you need to add addUrlRewrite() function to that collection ($categoryProducts).

So changes

<?php $product = $categoryProducts->getFirstItem();?>


$product = $categoryProducts->getFirstItem();?>

Also,please check Magento indexing Management is working or not at system

| improve this answer | |

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