This question already has an answer here:

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;?>

marked as duplicate by sv3n, Manoj Deswal, Prince Patel, Jai, liyakat Oct 17 '17 at 4:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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

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