Magento URL Key - thumbnail

Master Magento URL Key: A Ridiculously Simple Guide

by Robin Tran

It’s time to show you how you can perfect the Magento URL key.

Together, we will learn its definition, why it’s important, how to generate and troubleshoot problems such as invalid URL key Magento 2 import.

Let’s just jump right into it!

Magento URL Key: The How-to Textbook

What Is the Magento 2 URL Key?

Magento URL key is the exact path in the URL that is underlined in the picture below:

url-key-of-magento

As you can see, it is identical to the product mentioned in terms of content. 

Format-wise, it’s in lower case with hyphens to separate the word.

You can switch it up in the Search Engine Optimization section of the product information. 

edit-url-key

After that, a permanent redirect will happen automatically with your new Magento URL key.

Why is Magento URL Key Important?

Magento put it in the SEO apartment for a reason.

But it doesn’t stop there; in fact, there are so many reasons that make URL key unique and ingrained to the success of your store. 

Let’s take a look at the three most significant benefits of conducting Magento 2 generate url key:

UX Brownie Point

Everyone wants to know what they’re getting into. 

That’s why you need to use the URL key to tell what’s your page is about. Especially on the SERP:

the-listing-page

DON’T MISS OUT on our Magento 2 Import Export URL Rewrites to make your URL SEO-friendly!

The preferable structure giving site with a thoughtful URL key stands out on the listing page even if the meta description is all over the place. 

And you know what rhyme stands out? Sell out!

Rankings

The impact of the URL key on the ranking is minor and major at the same time. 

Let me explain.

While a URL key can improve your site’s search visibility, it doesn’t have a significant leg in the ranking algorithm.

Because if your content doesn’t live up to the expectations, your bounce rate will skyrocket and hurt your ranking.

cover-does-matter

However, if your content and product are amazing, but you craft your appearance poorly, no one will click on it. And that leads to ranking lower on the listing page.

Yes, “Don’t judge the book by its cover,” but if there are millions of books lying around, it’s better to have a stunning cover.

Just imagine which one of these two URLs you’re more likely to click?

preferable-url

Right?

Links

If you play your card right, a well-written URL key and its static URL can stand alone as anchor text. 

This function is helpful because a lot of social media do not allow placing URLs in the anchor text. All and all, it just further reinforces the UX point above.

Moreover, you can gain better chances of getting ranked by your keyword.

URL Key vs. URL Path

And this is how you differentiate url_key and url_path in Magento.

how-magento-2-duplicate-url-key-but-not-url-path

FOOD FOR THOUGHT: Magento 2 SEO guide – Everything you need to know

How to Generate Magento 2 URL Key?

So we know what it is and why it’s crucial. Now let’s move to how to create it.

There are two ways, and we will go through both of them

By Default Magento

The Magento 2 URL key is self-made. Magento self-produces it by lower case the product/category name and adding hyphens between words.

Otherwise, you can navigate to Catalog→Products→Search Engine Optimization and update the URL key as you like.

By Importing

This option will be an obvious choice for Magento stores with a lot of products. Because changing the URL key, one by one must be tedious at that point. 

  • So first, if you don’t have a CVS file of your products already, export one out.
  • At the Admin Panel, go to System -> Export -> in Entity Type choose Product, excluding all agents, but Product name, SKU, and URL key -> Continue.
  • Your file will be ready in a few minutes (depending on the number of your products)
  • After downloading the file, you can now change any URL key you want. Follow up, using Store Manager for Magento (this one is FREE by the way) to import your URL key!

Magento URL Key Troubleshooting 

Magento 2 URL Key for Specified Store Already Exists

If you run into this problem while importing your products. You need to check this.

First, fast check your CVS file to see if there are duplicate products. At the Home panel of Excel -> Conditional Formatting -> Highlight Cells Rules -> Duplicate Value -> Yes.

magento-url-key-for-specified-store already-exists-issue

Here, all duplicate values are highlighted. Now, you can sort them out even more for easy deleting. Right-click on any cell -> Filter -> Filter by Selected Cell’s Color. 

magento-2-duplicate-url-key-problem

If the problem doesn’t relate to cloning content, you need to tweak it around with coding. Special thanks to Mr. Toan Tam for the code. 

/**
 * Generate list based on categories
 *
 * @param int $storeId
 * @param Product $product
 * @param ObjectRegistry $productCategories
 * @return UrlRewrite[]
 */
public function generate($storeId, Product $product, ObjectRegistry $productCategories)
{
    $urls = [];
    foreach ($productCategories->getList() as $category) {
        $anchorCategoryIds = $category->getAnchorsAbove();
        if ($anchorCategoryIds) {
            foreach ($anchorCategoryIds as $anchorCategoryId) {
                //Default: $anchorCategory = $this->categoryRepository->get($anchorCategoryId);
                $anchorCategory = $this->categoryRepository->get($anchorCategoryId, $storeId);
                $urls[] = $this->urlRewriteFactory->create()
                    ->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)
                    ->setEntityId($product->getId())
                    ->setRequestPath(
                        $this->urlPathGenerator->getUrlPathWithSuffix(
                            $product,
                            $storeId,
                            $anchorCategory
                        )
                    )
                    ->setTargetPath(
                        $this->urlPathGenerator->getCanonicalUrlPath(
                            $product,
                            $anchorCategory
                        )
                    )
                    ->setStoreId($storeId)
                    ->setMetadata(['category_id' => $anchorCategory->getId()]);
            }
        }
    }

    return $urls;
}

Now, there should be no problem with your importing at all!

Invalid URL Key Magento 2 Import

So, this one problem can stem from a number of reasons. In this case, I highly suggest you specify your issue on these websites/forums:

This way, you can have multiple entries for answers which are always helpful. If you still struggling in understanding the guide and want to find an easier solution, let’s take some minutes and visit our Magento 2 addons. Hope it helps!

Wrap Up

So, that is it. Hopefully, this article from BSS Commerce will help you understand and master the Magento URL key. If you have any questions, don’t hesitate to ask! The comment section is always open. 

BSS Commerce is offering Magento web development services for businesses to optimize their
Magento performance. What should you collaborate with us?

– We have 11+ years of experience in the eCommerce industry
– Our dedicated services is rated 5 stars on reliable platforms like TrustPilot and Magento Marketplace
– We are proud to achieve 90% of customer returning rate which is really impressive

If you are looking for an exceptional Magento solutions, reach out to us now!

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.