I've been tasked with making the URLs for an old website "pretty"
It's a real estate website with a few dozen buildings and maybe 100ish total apartment listings.
Current urls are like: (i was able to remove .php
extension easily with .htaccess
)
example.com/about?building-id=65
example.com/about?apartment-id=35
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...
But for this example...
Ideally the URLs should be
example.com/about/building-name/
example.com/about/building-name/apartment-name
The building name and apartment name are both values stored in the database, with the id#s as the primary keys.
After researching this issue a bit, I've determined a couple different approaches
1) Dynamically Generate the .htaccess
file upon changes in admin
- I think I can do this right?
- It would explicitly rewrite just about every possible valid query string possibility ( up to couple hundred probably)
- I imagine this will cause some performance issues, and is probably not best practice.
- If its the easiest option, I'm ok with it being sloppy and bad practice as long as it works.
2) Create a controller and rewite all queries to index.php
which would put together all the views from here.
- This is a bit more out of my comfort zone, but probably considered the best practice?
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)
My Question(s)
Are these viable options and did I miss any alternative?
Which approach should I take?