Answers.Body: <p>I can think of a couple possible solutions here:</p>
  
  <p><strong>1. Rethink your url structure</strong><br>
  You could always remove the category segment from the url. Maybe create a field for the main category and then another field for all the categories, and use the main category field for your URL. Or you could fetch the first <code>productCategory</code> instead of the last one, so there's less chance of it changing. In my opinion you're going to have a lot of SEO issues if your url changes whenever you add a new <code>productCategory</code>, not to mention broken links and all sorts of other headaches.</p>
  
  <p><strong>2. Do some fancy stuff with routes and entry queries</strong><br>
  I think technically you could set up a route like <code>flowers/{productCategory}/{slug}</code> and then in your template do an entry query for an entry with that slug. But probably better to think over #1 and find a cleaner solution.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-29T10:07:15.160Z
Answers.Text: No 2 is on the radar and yes it feels dirty :) Will revisit no 1
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-26T20:07:01.633Z
Answers.LastActivityDate: 2019-04-26T20:07:01.633Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>I have a setup in Craft 2 like below:</p>
  
  <pre><code>Section: products
  Url format: flowers/{productCategory.last.uri}/{slug}
  
  Categories: 
  cat1 = Bouquets
  cat2 = Valentines days
  Url format: flowers/{slug}
  </code></pre>
  
  <p>The problem headache arises when I want to get the entry URL within a category template. It always gets the last category of the entry due to the URL format. So once valentines day is added as a second category then a normal bouquet entry URL goes from this:</p>
  
  <pre><code>/flowers/bouquets/entry-slug
  </code></pre>
  
  <p>to</p>
  
  <pre><code>/flowers/valentines-day/entry-slug
  </code></pre>
  
  <p>I solved this partly by making my bouquet URL out of the URL path:</p>
  
  <pre><code>            {% for entry in entries %}
                  {% set prodUrl = 'flowers/'~ seg2~ '/'~entry.slug %}
                   &lt;a href="{{ baseUrl }}{{ prodUrl }}" &gt;
  </code></pre>
  
  <p>However, the entry template now doesn't have the entry model.</p>
  
  <p>How do other people solve this multiple categories for the same content type issue?</p>
  
Tags: <categories><sections>
Title: How to manage multiple categories and entry url formats
ThreadText: # How to manage multiple categories and entry url formats
  
  (Asked by: username_0 on 2019-04-20)
  
  I have a setup in Craft 2 like below:
  
  ```
  Section: products
  Url format: flowers/{productCategory.last.uri}/{slug}
  
  Categories: 
  cat1 = Bouquets
  cat2 = Valentines days
  Url format: flowers/{slug}
  
  ```
  
  The problem headache arises when I want to get the entry URL within a category template. It always gets the last category of the entry due to the URL format. So once valentines day is added as a second category then a normal bouquet entry URL goes from this:
  
  ```
  /flowers/bouquets/entry-slug
  
  ```
  
  to
  
  ```
  /flowers/valentines-day/entry-slug
  
  ```
  
  I solved this partly by making my bouquet URL out of the URL path:
  
  ```
              {% for entry in entries %}
                  {% set prodUrl = 'flowers/'~ seg2~ '/'~entry.slug %}
                   <a href="{{ baseUrl }}{{ prodUrl }}" >
  
  ```
  
  However, the entry template now doesn't have the entry model.
  
  How do other people solve this multiple categories for the same content type issue?
  
  **Tags:** categories, sections
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-26. Score: 1 | Accepted answer
  
  I can think of a couple possible solutions here:
  
  **1. Rethink your url structure**  
  You could always remove the category segment from the url. Maybe create a field for the main category and then another field for all the categories, and use the main category field for your URL. Or you could fetch the first `productCategory` instead of the last one, so there's less chance of it changing. In my opinion you're going to have a lot of SEO issues if your url changes whenever you add a new `productCategory`, not to mention broken links and all sorts of other headaches.
  
  **2. Do some fancy stuff with routes and entry queries**  
  I think technically you could set up a route like `flowers/{productCategory}/{slug}` and then in your template do an entry query for an entry with that slug. But probably better to think over #1 and find a cleaner solution.
  
  > **Comments:**
  > **username_0**: No 2 is on the radar and yes it feels dirty :) Will revisit no 1  
  
  ---
  
  