2

I suspect this boils down to a feature request, but I'll start here in case there are any other ideas.

Basically, I want to be able to define multiple URL formats for a single section or category group.

Here is the scenario:

  • Section gear with URL format gear/{slug}
  • Category group productTypes with URL format gear/{slug}, {parent.uri}/{slug}
  • Section reviews with URL format reviews/{slug}.

What I want to do but can't, is define a second URL format for productTypes, with the format reviews/{slug}, and {parent.uri}/{slug}.

Similarly, I want to define a 2nd format for gear, of reviews/{slug}.

So I'd end up with:

  • gear/gear-entry/
  • gear/category/
  • reviews/category/
  • reviews/gear-entry/
  • reviews/review-entry/

So I really need Craft to know about those additional formats to avoid crossover URLs.

Routing and assigning the entry and category variables is not a problem, I'm really just concerned with the slug/uri validation.

3

So semantically, I don’t love the URL format you’re coming up with. I’d like to see something like /gear/{category}/{entry}

This gives you a few benefits

  • it’s semantically readable…
  • it gives you natural breadcrumbs for the hierarchy of content
  • it’s likely going to be better from an SEO perspective

Relevant feature request: https://github.com/craftcms/cms/issues/1189

| improve this answer | |
  • Changing the URL altogether could certainly make things easier. Your suggestion could odd with multiple category assignments and nesting. – Tim Kelty Aug 16 '16 at 18:02
1

If you're only worried about URL collisions, it looks like there's only a few places where your routes overlap:

  • gear/{slug} could match a gear entry or a category.
  • reviews/{slug} could match a category, gear entry, or review entry.

One easy way around this is to just just make some of these routes more specific. For example:

  • gear/{slug} (gear entry)
  • gear/category/{slug} (product type category)
  • reviews/category/{slug} (product type category)
  • reviews/gear/{slug} (gear entry)
  • reviews/{slug} (review entry)

Note: "category" above is the literal string, not the category's slug. But if "category" is too verbose, possibly just gear/cat/{slug} or gear/c/{slug}.

Or...

If you wanted to alter your URL formats minimally from your original scheme, another option would be to setup gear, productTypes, and reviews to all use the same route of reviews/{slug}. Craft will use a section's Entry URL Format when saving an entry to check for duplicate slugs.

  • reviews/{slug} (product type category)
  • reviews/{slug} (gear entry)
  • reviews/{slug} (review entry)

Then just add a "category" segment for gear to make sure gear entries don't clash with productTypes categories:

  • gear/{slug} (gear entry)
  • gear/category/{slug} (product type category)
| improve this answer | |
  • 1
    It does check the full URI for duplicates against any URL formats it knows about. Which is great, and the feature I'm trying to leverage. – Tim Kelty Aug 18 '16 at 2:56
  • Yep, your "category" segment solution works, and is actually what I'm doing currently. It would be nice if there were a way to define both formats in Craft though, so that Craft itself knew about all your URLs. Feature request: feedback.craftcms.com/forums/285221-feature-requests/… – Tim Kelty Aug 18 '16 at 3:01
  • You're right, @TimKelty! Craft does check other section Entry URL formats. Craft rulez. Thanks for bringing that to my attention. I'll update my answer. – Alex Roper Aug 18 '16 at 8:25
  • 1
    Yeah, it's a really nice feature! Would be even better given something like my FR, which would allow Craft to know about ALL of your URLs. – Tim Kelty Aug 18 '16 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.