How to configure Magento 2 SEO-friendly URLs?

Is Magento 2 SEO friendly? If you make all the basic configurations for its optimization, it's definitely SEO friendly.

SEO-friendly URLs configuration is no less important than duplicate content avoidance, XML/ HTML sitemaps creation and other SEO settings. Here we’ll consider the basic URL configurations available in Magento 2.

→ Automate routine SEO tasks by using our all-in-one SEO Toolkit

How to set Magento 2 SEO-friendly URLs? 

  • Log in to the Admin Panel and go to Stores>Configuration and choose the Web tab under the General menu:


  • Expand the Search Engine Optimization drop-down menu:


  • Make sure the Use Web Server Rewrites option is set to ‘Yes’. If not, untick Use system value and change the configuration. The setting will allow you to include category path for product URLs. 
  • Save the changes and clear the cache.

Besides, you may create an SEO-friendly Category URL key for each store view.

  • For this, navigate to Products>Categories>Search Engine Optimization and expand the drop-down menu:


  • Fill in the Meta Title, Meta Keywords, Meta Description fields for the categories you want.

If you need a wider set of configurations, navigate to Stores>Configuration>Catalog>Catalog>Search Engine Optimization to enable/disable all the available product URL options:


Here you can enable:

  • popular search terms;
  • choose product and category URL suffixes;
  • enable to use category path for product URLs and others. 

To see more information about canonical tag configuration, see here.

For those merchants who offer bazillion products in Magento 2, filter products by attributes is the only way to make the clients’ shopping faster and easier. However, the filter-by-attributes feature can also be used for SEO purposes. Thus, you can specify custom meta tags, short URLs for filter result pages and define any URL keys for pages with filter results.

To improve the UX further, you can also add Magento 2 Elastic Search extension that makes in-store search fast and relevant.

How can I get the SEO URL of a product in Magento 2?

To get the SEO URL of a product in Magento 2, you can use the following code snippet:

$product = $block->getProduct(); 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$url = $objectManager->get('Magento\Catalog\Model\Product\Url')->getUrl($product);

In this code, we first obtain the product object and then use the getUrl() method of the Magento\Catalog\Model\Product\Url class to get the product's SEO URL. You can customize this code to fit your specific requirements, such as getting the URL of a specific product by ID or using dependency injection instead of the ObjectManager.

How can we help you?

Didn’t you find the answer to your question? We are always happy to help you out.