Remove category path/catelog path from product URL in magento

Remove category path/catelog path from product URL in magento

August 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Remove category path/catelog path from product URL in magento

Removing Category Path From Product URLs in Magento

As a new Magento developer, you might face challenges when trying to customize your store’s URL structure. One common issue is the presence of the category path in product URLs. Fortunately, this can be easily resolved with some configuration changes and minor code modifications.

Understanding the Default URL Structure

By default, Magento follows a convention that includes the category path in the product URL:

www.websiteurl.com/catalog/category/view/s/large-beverage-glasses/id/61/

This structure is designed to preserve the site’s SEO hierarchy and navigation flow. However, for many stores, especially those with clean, straightforward category structures, this can make URLs appear overly complex.

Removing Category Path: The Basic Approach

The goal is to achieve a simplified URL like this:

www.websiteurl.com/glasses/large-beverage-glass/

To accomplish this, you need to configure Magento’s SEO settings and apply some changes to the core codebase.

Step 1: Configure Magento SEO Settings

  1. Log in to your Magento admin panel.
  2. Navigate to Stores > Configuration > Catalog > Search Engine Optimization.
  3. Set ‘Use Categories Path for Product URLs’ to No.
  4. Click Save Config.

This setting tells Magento not to include the category path in product URLs, but it doesn’t actually remove them yet.

Step 2: Modify Core Code

The next step involves editing a core file to ensure that Magento generates the desired URL structure.

  1. Navigate to app/code/core/Mage/Catalog/Model/Product.php.
  2. Locate the function getUrlPath() (around line 340).
  3. Replace the existing code with this:
public function getUrlPath()
{
    $path = parent::getUrlPath();
    return str_replace('catalog/category/view/id/', '', $path);
}

This modification removes the ‘catalog/category/view/id/’ portion from the URL, which effectively strips out the category ID.

Best Practices and Alternatives

While this approach works, it’s important to consider a few things:

  1. Backup your files: Always backup your core files before making any modifications.
  2. Avoid directly editing core files: In a production environment, it’s better to use a custom theme or module to override the core functionality. This ensures that your changes survive Magento updates and upgrades.
  3. Test thoroughly: After making these changes, test all product URLs to ensure they work correctly.

For more detailed guides on URL rewriting and SEO optimization in Magento, I recommend checking out our comprehensive tutorials at LaravelCompany.

Conclusion

Removing the category path from product URLs is a straightforward process that requires some configuration changes and minimal code modifications. By following these steps, you can achieve a cleaner, more user-friendly URL structure for your Magento store.

Remember to always backup your files and test thoroughly after making any core changes. If you’re unsure about any aspect of this process or need further assistance, don’t hesitate to contact the support team at LaravelCompany.

Catalog Performance Admin Configuration

Our network