title: mod_rewrite ecommerce URL design
body: <p>I have problems with how I should structure my product listing pages, products pages, webpages.</p>
  
  <p>It roughly translate into this:</p>
  
  <ol>
  <li><code>/bags/nicebag.html</code> = <code>/product.php?product=nicebag&amp;category=bags</code></li>
  <li><code>/nicebag.html</code> = <code>/product.php?product=nice_bag</code></li>
  <li><code>/bags</code> = <code>productlisting.php?&amp;category=bags</code></li>
  </ol>
  
  <p>Problem is that webpages will share same URL structure as no.2 in the list
  <code>/contact.html</code> = <code>page.php?page=contact</code></p>
  
  <p>The reason why it is not listed in .htaccess separatly is that webpages can have different names. And even the same page can be in multiple languages.</p>
  
  <p>The reason of no. 1 and 2 is not combined, is that sometimes I just want to reference only to the product since it can be in multiple categories.</p>
  
  <p>What kind of structure do you suggest?</p>
  
  <p><strong>.htaccess</strong></p>
  
  <pre><code># Mod rewrite enabled.
  Options +FollowSymLinks
  RewriteEngine on
  
  # ---- Rules ----
  
  # product.php (Search for category &amp; product name)
  RewriteRule ^([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)\.html?$ product.php?prod_id=$2&amp;cid=$1 [NC,L]
  
  # productlisting.php (Search for category)
  RewriteRule ^([A-Za-z0-9-_]+)?$ productlisting.php?&amp;cid=$1 [NC,L]
  </code></pre>