# SEO - Friendly Product URLs

> Pattern-based product URL keys built from any attribute combination — generated on the admin form, bulk-regeneratable via CLI, collision-protected.

<Admonition type="warning" title="Important">
qoliber SEO Friendly Product URLs is a stand-alone commercial product, currently available to qoliber extensions licensees only.
</Admonition>

## General Information

A product's URL is one of the strongest, most-visible SEO signals on an e-commerce site. It's also the field nobody has time to maintain by hand. Most Magento stores ship with URL keys that match whatever Magento auto-generates on first save — usually just the product name, without brand, model number, colour or any of the other attributes a customer might search for.

The Qoliber SEO Friendly Product URLs extension lets you define a URL pattern using any combination of product attributes — `{brand}-{name}-{sku}`, `{name}-{color}-{material}`, whatever fits your catalogue — and applies it consistently across thousands of products, with safety nets against URL collisions and accidental overwrites of existing routes.

## What Does This Extension Do?

- **Configurable URL pattern** — define a template using attribute codes in curly braces. Examples: `{name}-{sku}`, `{brand}-{color}-{size}`, `{manufacturer}-{model}-{year}`.
- **Admin "Generate URL" button** in the product SEO section — generates a fresh URL key on demand without leaving the product edit form.
- **Bulk regeneration CLI** — `bin/magento qoliber:seo:regenerate-urls` with `--entity-id-from`, `--entity-id-to` and `--store-id` options. Reapply the pattern across the entire catalogue or any subrange.
- **Select/multiselect attribute label resolution** — uses the human label ("red") in the URL, not the option ID ("93").
- **Magento URL rewrite integration** — every regenerated URL creates a proper rewrite, and legacy URLs continue to resolve via 301 redirects.
- **Cross-entity collision detection** — checks the URL rewrite table across every entity type (products, categories, CMS pages) before writing, so you can't accidentally overwrite `/about-us` with a product URL.
- **Transactional batch writes** — bulk regeneration wraps both `catalog_product_entity_varchar` and `url_rewrite` updates in a single DB transaction. Partial failures roll back cleanly; you never end up with a half-applied state.
- **Scope-limited 301 cleanup** — the module only touches rewrites it created itself (identified by description marker). Manually-curated 301 redirects are never disturbed.

## Why Is This a Game Changer?

- **Migration-grade safety.** Most "URL rewriter" extensions for Magento happily overwrite a CMS-page URL with a product URL because they only check within their own entity scope. Ours doesn't.
- **Predictable, auditable, repeatable.** The same pattern applied to the same data produces the same URLs every time. Run it once, run it again after a catalogue import, run it on staging — same result.
- **The admin actually does something useful.** A "Generate URL" button on the product form means even a one-off product gets a consistent URL without forcing the merchant to read the docs.
- **CLI for bulk operations.** When you import 10,000 products from an ERP, the CLI processes the lot in a single transactional run with progress reporting.

## How Does It Work?

When you configure a URL pattern (e.g., `{brand}-{name}-{sku}`) and click **Generate URL** on a product (or run the CLI):

1. The module reads the configured attribute values for the product.
2. Resolves option IDs to human labels for select/multiselect attributes.
3. Slugifies the pattern with the resolved values.
4. Checks the resulting path against the entire `url_rewrite` table to detect cross-entity collisions.
5. On collision, falls back to a deduplicated variant or reports the conflict in the CLI output.
6. Writes the new URL key and creates a 301 redirect from the previous URL.

### Examples

| Pattern | Product attributes | Generated URL key |
|---------|--------------------|--------------------|
| `{name}-{sku}` | "Yoga Pants", MP01 | `yoga-pants-mp01` |
| `{brand}-{name}-{color}` | Lululemon, Yoga Pants, Blue | `lululemon-yoga-pants-blue` |
| `{manufacturer}-{model}-{year}` | Bosch, GSB 18V-21, 2024 | `bosch-gsb-18v-21-2024` |

### Configuration at a glance

Find the module under **Stores → Configuration → Qoliber → SEO: Product Friendly URLs**. Set your pattern, choose which attributes are eligible to appear in templates, and decide whether the admin button regenerates URL keys for already-published products.

## What's New in 2.1

- **Critical collision-prevention fix** — dedup checks now scan all entity types in `url_rewrite`, not just products. Pre-2.1 installs could silently overwrite CMS-page or category URLs with product URLs.
- **Transactional batch regeneration** — bulk CLI runs wrap product-entity and url-rewrite updates in a single DB transaction; partial failures roll back cleanly.
- **Scope-limited 301 cleanup** — the module's deletes only touch rewrites it created itself (identified via the `Generated by Qoliber_SeoFriendlyProductUrls` marker). Manually-curated 301s are safe.
