Answers.Body: <p>Brad nails the problem in <a href="https://craftcms.stackexchange.com/questions/10578/how-do-i-create-an-advanced-route-with-multiple-slugs#comment13751_10578">his comment</a>:</p>
  
  <blockquote>
    <p>The error is because you've got two named subpatterns with the same name (<code>&lt;slug&gt;</code>)</p>
  </blockquote>
  
  <p>And the solution is simple... <strong>Change the name(s) of your subpattern(s)</strong>.</p>
  
  <p>The term <code>slug</code> is just a convention of Craft. It doesn't matter what the names are, they can be anything useful to you:</p>
  
  <pre class="lang-none prettyprint-override"><code>(?P&lt;domain&gt;[^/]+)/(?P&lt;category&gt;[^/]+)/feed
  </code></pre>
  
  <p>Whatever values match those named patterns are automatically <strong>passed into the Twig template as "magic" variables</strong>. So your Twig template can now make use of the <code>domain</code> and <code>category</code> values.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-15T06:20:43.743Z
Answers.Text: It's also possible to make segments optional. See this question [Is it possible to define optional route segments?](http://craftcms.stackexchange.com/q/8568/125).
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-15T06:03:46.650Z
Answers.LastActivityDate: 2015-07-15T06:03:46.650Z
Answers.LastEditDate: 2017-04-13T12:50:59.930Z
Answers.UserDisplayName: Lindsey D
Body: <p>I'm trying to create a route for an RSS feed which allows for the following routes. </p>
  
  <pre><code>domain/feed
  domain/category/feed
  domain/category/subcategory/feed
  </code></pre>
  
  <p>I have the first two routes working and the category fetching logic looks okay to me.</p>
  
  <p>So far in my routes file I have the following</p>
  
  <pre><code>'feed' =&gt; 'feed/_index.twig',
  '(?P&lt;slug&gt;[^/]+)/feed' =&gt; 'feed/_index',
  
  // Additional New route
  '(?P&lt;slug&gt;[^/]+)/(?P&lt;slug&gt;[^/]+)/feed' =&gt; 'feed/_index',
  </code></pre>
  
  <p>That last line was added recently as I thought the child category would include the parent category in its route.</p>
  
  <p>I either get a 404 error without that new route, or when I do add that third route I get the following error</p>
  
  <pre><code>preg_match(): Compilation failed: two named subpatterns have the same    
  name at offset 27 (craft/app/etc/web/UrlManager.php:387)
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-07-15T02:02:27.393Z
Comments.Text: The error is because you've got two named subpatterns with the same name (`<slug>`).  According to http://stackoverflow.com/a/7166444/684, you can do that as long as you use the `(?J)` option in your pattern.  Not sure if that's going to solve your overall problem, so just adding this as a comment.
Comments.UserDisplayName: Brad Bell
Tags: <routes><php><slug><regex>
Title: How do I create an advanced route with multiple slugs?
ThreadText: # How do I create an advanced route with multiple slugs?
  
  (Asked by: username_0 on 2015-07-15)
  
  I'm trying to create a route for an RSS feed which allows for the following routes.
  
  ```
  domain/feed
  domain/category/feed
  domain/category/subcategory/feed
  
  ```
  
  I have the first two routes working and the category fetching logic looks okay to me.
  
  So far in my routes file I have the following
  
  ```
  'feed' => 'feed/_index.twig',
  '(?P<slug>[^/]+)/feed' => 'feed/_index',
  
  // Additional New route
  '(?P<slug>[^/]+)/(?P<slug>[^/]+)/feed' => 'feed/_index',
  
  ```
  
  That last line was added recently as I thought the child category would include the parent category in its route.
  
  I either get a 404 error without that new route, or when I do add that third route I get the following error
  
  ```
  preg_match(): Compilation failed: two named subpatterns have the same    
  name at offset 27 (craft/app/etc/web/UrlManager.php:387)
  
  ```
  
  Any help would be greatly appreciated.
  
  **Tags:** routes, php, slug, regex
  
  > **Comments:**
  > **username_1**: The error is because you've got two named subpatterns with the same name (`<slug>`).  According to http://stackoverflow.com/a/7166444/684, you can do that as long as you use the `(?J)` option in your pattern.  Not sure if that's going to solve your overall problem, so just adding this as a comment.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-07-15. Score: 6 | Accepted answer
  
  username_1 nails the problem in [his comment](https://craftcms.stackexchange.com/questions/10578/how-do-i-create-an-advanced-route-with-multiple-slugs#comment13751_10578):
  
  > The error is because you've got two named subpatterns with the same name (`<slug>`)
  
  And the solution is simple... **Change the name(s) of your subpattern(s)**.
  
  The term `slug` is just a convention of Craft. It doesn't matter what the names are, they can be anything useful to you:
  
  ```none
  (?P<domain>[^/]+)/(?P<category>[^/]+)/feed
  
  ```
  
  Whatever values match those named patterns are automatically **passed into the Twig template as "magic" variables**. So your Twig template can now make use of the `domain` and `category` values.
  
  > **Comments:**
  > **username_3**: It's also possible to make segments optional. See this question [Is it possible to define optional route segments?](http://craftcms.stackexchange.com/q/8568/125).  
  
  ---
  
  