title: How to change my URL structure on old php site using database values?
body: <p>I've been tasked with making the URLs for an old website "pretty"</p>
  
  <p>It's a real estate website with a few dozen buildings and maybe 100ish total apartment listings.</p>
  
  <p>Current urls are like: (i was able to remove <code>.php</code> extension easily with <code>.htaccess</code>)</p>
  
  <pre><code>example.com/about?building-id=65
  example.com/about?apartment-id=35
  </code></pre>
  
  <p>It gets considerably more complicated than that, with some search pages, different listings views, a contact form page that gets sent a building or apt id to prefil the form with some info, etc...</p>
  
  <p>But for this example...</p>
  
  <p>Ideally the URLs should be</p>
  
  <pre><code>example.com/about/building-name/
  example.com/about/building-name/apartment-name
  </code></pre>
  
  <p>The building name and apartment name are both values stored in the database, with the id#s as the primary keys.</p>
  
  <p>After researching this issue a bit, I've determined a couple different approaches</p>
  
  <p>1) <strong>Dynamically Generate the <code>.htaccess</code> file upon changes in admin</strong>  </p>
  
  <ul>
  <li>I think I can do this right? </li>
  <li>It would explicitly rewrite just about every possible valid query string possibility ( up to couple hundred probably)</li>
  <li>I imagine this will cause some performance issues, and is probably not best practice.</li>
  <li>If its the easiest option, I'm ok with it being sloppy and bad practice as long as it works.</li>
  </ul>
  
  <p>2) <strong>Create a <em>controller</em> and rewite all queries to <code>index.php</code> which would put together all the views from here.</strong></p>
  
  <ul>
  <li>This is a bit more out of my comfort zone, but probably considered the best practice?</li>
  </ul>
  
  <p><em>The site is seriously old, and poorly put together (1000s of lines of custom (non OOP) php with lots of code duplication) For that matter, its really 2 different sites sharing the one database, and most of the code base (2nd was created some time ago with a copy-paste of original code base and has since grown apart)</em></p>
  
  <hr>
  
  <p><strong>My Question(s)</strong></p>
  
  <ul>
  <li><p>Are these viable options and did I miss any alternative?</p></li>
  <li><p>Which approach should I take?</p></li>
  </ul>