Setting Up SEO-Friendly URLs and 301 Redirects in Magento 2
Search engines and shoppers both judge a store by its URLs before they even see a product page. A messy URL structure full of query strings, duplicate paths, or broken links after a re-platform quietly bleeds organic traffic. Getting SEO-friendly URLs and 301 redirects in Magento 2 right is one of the highest-leverage technical SEO tasks a Magento merchant can tackle, and most of it can be done without touching a single line of code.
This guide walks through the core Magento 2 configuration settings, how URL rewrites work under the hood, and how to manage 301 redirects safely when you change category structures, rename products, or migrate a store.
Why URL Structure Matters for Magento SEO
Magento's default installation is already reasonably search-friendly, but out of the box it can still generate:
- Long, keyword-stuffed or duplicate paths when categories are nested deeply
- URLs with
.htmlsuffixes mixed inconsistently across products and categories - Orphaned URLs that return 404s after a product is deleted or a category is renamed
- Duplicate content issues when the same product is reachable through multiple category paths
Each of these dilutes crawl budget and can cause ranking pages to lose their accumulated authority. Fixing the structure early â before a catalog grows to thousands of SKUs â saves a lot of redirect cleanup later.
Step 1: Enable Web Server Rewrites
Before anything else, confirm that clean URLs are actually enabled. Go to:
StoresâēConfigurationâēGeneralâēWebâēSearch Engine Optimization
Set Use Web Server Rewrites to Yes. This strips index.php/ out of your URLs, which is non-negotiable for a professional storefront. If you're on Apache, make sure .htaccess rewrite rules are active; on Nginx, verify your server block includes Magento's standard try_files and rewrite directives from the sample configuration Magento ships with.
Step 2: Configure Category and Product URL Options
Still under StoresâēConfigurationâēCatalogâēCatalogâēSearch Engine Optimization, review these settings carefully:
- Product URL Suffix â typically
.html. Keep it consistent across the catalog; changing it later regenerates every product URL and requires a full redirect pass. - Category URL Suffix â same logic applies. Many stores leave this blank or set it to
.htmlas well. - Use Categories Path for Product URLs â decide deliberately here. Setting it to
Yesproduces URLs like/category/product-name.html, which can be useful for category-level relevance but creates a new URL every time a product is reassigned to a different category. Setting it toNoproduces flatter, more stable URLs like/product-name.html. - Create Permanent Redirect for URLs if URL Key Changed â set this to
Yes. This single toggle is what automatically generates 301 redirects whenever a product or category URL key changes, and it should almost always be enabled in production.
For most catalogs, especially larger ones with products that move between categories over time, disabling the categories path for product URLs reduces the number of redirects you'll need to manage long-term.
Step 3: Set Clean, Manual URL Keys
Magento auto-generates a URL key from the product or category name, but auto-generated keys often include stop words, dates, or awkward characters. Best practice:
- Keep URL keys short, lowercase, hyphen-separated, and free of stop words (
and,the,for) - Avoid embedding attributes that change often, such as size or color, in the URL key
- Set the URL key manually on high-value pages rather than relying purely on the auto-generated value from the product name
You can bulk-edit URL keys through Catalog > Products, selecting products and using the inline grid editor, or via an exported/re-imported CSV for larger catalogs. Just remember: every URL key change triggers a redirect only if the setting from Step 2 is enabled.
Step 4: Understand How Magento Stores URL Rewrites
Every clean URL in Magento is stored as a row in the url_rewrite database table, mapping a request_path to a target_path. When you change a URL key, Magento doesn't delete the old row â it converts it into a redirect rule pointing to the new path, provided permanent redirects are enabled.
You can inspect and manage these directly from the admin panel:
MarketingâēSEO & SearchâēURL Rewrites
Here you'll see three types of entries:
- Custom â manually created rewrites or redirects
- Product / Category / CMS Page â automatically generated by the catalog
- Redirect Type â either
No,Temporary (302), orPermanent (301)
For SEO purposes, always use Permanent (301) when a URL change is final. Temporary redirects tell search engines not to transfer ranking signals, which defeats the purpose in almost every real-world scenario except short-lived promotions or A/B tests.
Step 5: Create Manual 301 Redirects
Sometimes you need a redirect that Magento didn't generate automatically â for example, redirecting an old marketing landing page, a discontinued category, or a URL inherited from a previous platform migration.
To add one manually:
- Go to MarketingâēSEO & SearchâēURL Rewrites and click Add New Redirect
- Choose Custom as the redirect type
- Enter the Request Path (the old URL, without the domain)
- Enter the Target Path (the new URL it should point to)
- Set Redirect Type to
Permanent (301) - Save
A few rules to keep redirects healthy:
- Never redirect a URL to itself or create a loop between two paths
- Avoid chains â if page A redirects to B, and B redirects to C, update A to point directly to C
- Don't redirect everything to the homepage as a catch-all; it signals low relevance to search engines and frustrates users who expected specific content
- Keep redirects in place indefinitely for pages that had external backlinks or indexed history â removing them later can revive old 404s
Handling Bulk Redirects During Migrations or Re-Platforming
Manually creating redirects one by one works fine for occasional changes, but it becomes unmanageable during a large catalog restructuring, a domain migration, or when merging multiple stores into one Magento instance. In these situations, you typically need to:
- Export the full list of old URLs (from server logs, an XML sitemap, or the previous platform's database)
- Map each old URL to its corresponding new Magento URL
- Import hundreds or thousands of redirect rules at once rather than through the admin grid
Magento's core admin UI doesn't offer a native bulk import/export for URL rewrites, which is where a dedicated redirect management tool becomes practical. If you're planning a large-scale URL restructuring, a solution like the Magento 2 permanent redirects and URL rewrite management extension can handle bulk CSV imports, pattern-based redirects, and ongoing 404 monitoring without requiring manual entry for every single path â which is particularly valuable when redirect counts run into the thousands after a migration.
Step 6: Monitor for 404s After Any URL Change
Even with permanent redirects enabled, gaps happen â especially when:
- Products are deleted rather than disabled, which removes their URL rewrite entirely
- Categories are deleted instead of redirected
- Third-party integrations or old marketing emails still reference legacy URLs
- A theme or extension generates URLs outside Magento's standard rewrite system
Regularly check Google Search Console under PagesâēNot Found (404) and cross-reference against your server logs. Any 404 that still receives traffic or has backlinks should get a redirect rule.
It's also worth periodically crawling your own site with a desktop crawler to catch broken internal links that point to outdated URLs, since internal 404s waste crawl budget even if external search traffic isn't affected yet.
Common Mistakes to Avoid
Disabling instead of deleting, without checking redirects. Disabling a product hides it from the storefront but keeps its URL rewrite active by default, so this usually doesn't cause a 404. Deleting a product removes the rewrite, so if you need the URL gone permanently, delete the product and manually add a 301 to a relevant category or replacement product.
Changing the URL suffix on a live store. Switching from .html to no suffix (or vice versa) regenerates every single product and category URL. Unless you're prepared to verify that every old URL now correctly redirects to its new suffix version, avoid this change on an established store with existing search rankings.
Relying only on canonical tags instead of redirects. Canonical tags tell search engines which version of a page is preferred, but they don't fix a broken link for an actual visitor, and they carry less weight than a proper 301 for consolidating ranking signals. Use both together: canonicals for legitimate duplicate content variations (like sorting or filter parameters), and 301s for pages that have permanently moved.
Forgetting store view and multi-language URLs. If you run multiple store views or language versions, URL rewrites are typically scoped per store view. A redirect added for the default store view won't automatically apply to a secondary store view â check the Store View dropdown when creating rewrites in a multi-store setup.
Step 7: Reindex After Bulk URL Changes
After any significant batch of URL key changes or redirect imports, run:
php bin/magento indexer:reindex catalog_url_rewriteIf you're on scheduled indexing rather than \"update on save,\" also confirm the catalog_url_rewrite indexer status shows Ready in SystemâēIndex Management before assuming the changes are live. Clear the cache afterward:
php bin/magento cache:flushA Practical Checklist
Before closing out any URL restructuring project, confirm:
- Web server rewrites are enabled and clean URLs work without
index.php - Permanent redirect generation is turned on for URL key changes
- URL keys are clean, lowercase, and free of stop words on priority pages
- Every intentionally removed page has a corresponding 301, not a 404
- No redirect chains or loops exist in the
url_rewritetable - Redirects are scoped correctly across store views if running multi-store
- The
catalog_url_rewriteindexer has been run after bulk changes - Google Search Console shows a declining, not growing, 404 count over time
Final Thoughts
SEO-friendly URLs aren't a one-time setup task â they're an ongoing discipline that touches every product edit, category reorganization, and migration project a Magento store goes through. The native admin tools cover the basics well: clean URL configuration, automatic redirect generation on key changes, and a manual rewrite grid for edge cases. Where native Magento falls short is scale â bulk imports, pattern matching, and proactive 404 monitoring across a large catalog.
Getting the fundamentals right early, and having a reliable process (or tool) for handling redirects at volume, protects the search rankings your store has already earned and keeps both crawlers and customers landing exactly where they expect to.