title: .htaccess rewrite for date i.e. /2012/12/31
body: <p>I am trying to create some rewrite rules to organize content by date via URL in a short, readable way.</p>
  
  <p>i.e.</p>
  
  <pre><code>http://mysite.com/post/index.php?a=Dave&amp;b=2012&amp;c=12&amp;d=31&amp;e=1
  http://mysite.com/post/index.php?a=Dave&amp;b=2012&amp;c=12&amp;d=31
  http://mysite.com/post/index.php?a=Dave&amp;b=2012&amp;c=12
  http://mysite.com/post/index.php?a=Dave&amp;b=2012
  http://mysite.com/post/index.php?a=Dave&amp;b=all
  </code></pre>
  
  <p>becomes</p>
  
  <pre><code>http://mysite.com/post/Dave/2012/12/31/1
  http://mysite.com/post/Dave/2012/12/31
  http://mysite.com/post/Dave/2012/12
  http://mysite.com/post/Dave/2012
  http://mysite.com/post/Dave/all
  </code></pre>
  
  <p>This is the .htaccess I have in //mysite.com/post/</p>
  
  <pre><code>RewriteEngine On
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?([0-9]+)/?([0-9]+)/?([0-9]+)?$ index.php?a=$1&amp;b=$2&amp;c=$3&amp;d=$4&amp;e=$5 [L,NC,QSA]
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?([0-9]+)/?([0-9]+)/?([0-9]+)/?$ index.php?a=$1&amp;b=$2&amp;c=$3&amp;d=$4&amp;e=$5 [L,NC,QSA]
  
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?([0-9]+)/?([0-9]+)?$ index.php?a=$1&amp;b=$2&amp;c=$3&amp;d=$4 [L,NC,QSA]
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?([0-9]+)/?([0-9]+)/?$ index.php?a=$1&amp;b=$2&amp;c=$3&amp;d=$4 [L,NC,QSA]
  
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?([0-9]+)?$ index.php?a=$1&amp;b=$2&amp;c=$3 [L,NC,QSA]
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?([0-9]+)/?$ index.php?a=$1&amp;b=$2&amp;c=$3 [L,NC,QSA]
  
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)?$ index.php?a=$1&amp;b=$2 [L,NC,QSA]
  RewriteRule ^([a-zA-Z0-9_-]+)/?([a-zA-Z0-9]+)/?$ index.php?a=$1&amp;b=$2 [L,NC,QSA]
  
  RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?a=$1 [L,NC,QSA]
  RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?a=$1 [L,NC,QSA]
  </code></pre>
  
  <p>Now the problem is some of the URLs don't work. From the above examples, three of them work as expected. but the others output in these ways:</p>
  
  <pre><code>URL: http://mysite.com/post/Dave/2012/12
  OUTPUTS:
      a =&gt; Dave
      b =&gt; 2012
      c =&gt; 1
      d =&gt; 2
  URL: http://mysite.com/post/Dave/2012
  OUTPUTS:
      a =&gt; Dave
      b =&gt; 20
      c =&gt; 1
      d =&gt; 2
  </code></pre>
  
  <p>And this is obviously not the correct values, apparently splitting up the number across the other variables.</p>
  
  <p>Why does it do this and what must I do to fix it?</p>