title: Switch-based URL routing in PHP
body: <p>What I'm currently doing is this:</p>
  
  <p>I have a <code>$path</code> variable, which is everything after <em>index.php/</em> (which I hide with .htaccess) up to a question mark to ignore the querystring.</p>
  
  <p>Then I use a <code>switch</code> with <code>preg_match</code> cases on that variable to determine what script it should call. For example:</p>
  
  <pre><code>switch (true)
  {  
    case preg_match('{products/view/(?P&lt;id&gt;\d+)/?}', $path, $params): 
      require 'view_product.php'; 
    break;
  
    ...  
  
    default:
      require '404.php';
    break;
  } 
  </code></pre>
  
  <p>This way I can access the product id just using <code>$params['id']</code> and, if needed, use the querystring for filtering, pagination, etc.</p>
  
  <p>Is there anything wrong with this approach?</p>