title: WordPress - Rewrite rules with multiple parameters
body: <p>I'm setting up a WordPress page that would normally accept two querystring parameters. Our host prefers the use of rewrite rules instead of querystrings, so I have to take that approach. </p>
  
  <p>So where I'd normally do this:</p>
  
  <p><strong>domain.com/animal-page.php?animal=dog&amp;color=brown</strong></p>
  
  <p>I have to do this:</p>
  
  <p><strong>domain.com/animal-page/animal/dog/color/brown</strong></p>
  
  <p>The problem I am running into is that the second querystring parameter is optional. </p>
  
  <p>A rewrite rule like this wouldn't work:</p>
  
  <pre><code>add_rewrite_rule(
      '([\-\w+]*)/animal/([\w+]*)/color/([\w+]*)', 
      'index.php?pagename=$matches[1]&amp;animal=$matches[2]&amp;color=$matches[3]',
      'top'
  );  
  </code></pre>
  
  <p>...because if the color parameter is left off the URL (which is a possibility), that Regex fails. </p>
  
  <p>I've also tried making query param (color) and value (brown) optional in the Regex, and it still doesn't work:</p>
  
  <pre><code>add_rewrite_rule( 
          '([\-\w+]*)/animal/([\w+]*)(\/color\/?)([\w+]*)',
           'index.php?pagename=$matches[1]animal=$matches[2]&amp;$matches[3]=$matches[4]', 
          'top'
  )
  </code></pre>
  
  <p>My question is: Is there a way to make the second query parameter optional? I want the page to react appropriately if the 'color' parameter is left off the URL. </p>
  
  <p>Thanks, </p>