title: .htaccess rewrite rules to backbone router conversions
body: <p>I've done some digging around the interweb but nothing's making itself obvious.</p>
  
  <p>I'm looking to integrate a custom CMS with backbone so that a page can be loaded either with a raw http request or via a switch in 'state' through backbone. The CMS currently is focussed on  automating rewrite rules for it's route/urls via htaccess/mod-rewrite however backbone uses a different formatting structure for it's internal routes. </p>
  
  <p>I would like it if the CMS could translate it's rewrite rules into a the backbone format so that whenever a page is added to the CMS, backbone becomes aware of it and automatically updates itself. So for example the CMS outputs a load of page like this to a global SiteMap object:</p>
  
  <pre><code>....
  "contact"       =&gt; array(
          "key"       =&gt;      "contact",
          "url"       =&gt;      "^(en|fr|de)/contact/$",
          "type"      =&gt;      "page",
          "template"  =&gt;      "contact",
          "method"    =&gt;      "contact",
          "sitemap"   =&gt;      TRUE,
          //other page config vars etc
      ),//..and so on
  ...
  </code></pre>
  
  <p>there is then a parser which which writes a rule to the .htaccess like so:</p>
  
  <pre><code>RewriteRule ^(en|fr|de)/contact$ index.php?page=contact&amp;lang=$1&amp;section=$2
  </code></pre>
  
  <p><strong>QUESTION:</strong></p>
  
  <p>Obviously the <a href="http://backbonejs.org/#Router" rel="nofollow">backbone router format</a> is a little different and would require quite a lot of translation work to be done in PHP in order to output a nice clean router config.
  I can't believe I'm the first person to come across something like this as it would seem that this is a necessary step in trying to integrate a Backbone app to a CMS. Can anyone point me in the direction of some method of translating these string formats? Perhaps I'm approaching this the wrong way?</p>
  
  <p>Thanks very much indeed.</p>