g1smd - 11:01 pm on Aug 16, 2012 (gmt 0)
So I create a php look up page, that says if page id=1, then url=name?
No. Other way round. When user requests
example.com/page-name the request is rewritten (that's rewritten not redirected) to
/page-generator.php?name=page-name which looks up which record number that page name matches (sends 404 header and error message if no match) and then fetches the content from the database, assembles the page and sends it out.
Use extensionless URLs and a specific RegEx pattern that accepts only extensionless requests so that your system doesn't try to rewrite requests for robots.txt or for css and js files etc.
For the URLs, I prefer to include the ID number at the beginning (like
/1-page-name or similar), making it easier to fetch the content, and to allow the page name to be changed without changing the ID. Before the content is fetched, the php script does a look up to ensure the requested page name is correct for the requested page number. If they don't match, it sends a redirect to the correct URL.