I am trying to build a "standard" website in which the path to articles have SEO friendly URL Something like this:
www.test.com/library/book-34/chatper-4/page-10/
The website is build with PHP and mySQL. In this example we access the content of a page from a given chapter of an e-book. As for reasons which can easily be found on the web, I'd like to use this form rather than:
www.test.com/library.php?book=34&chap=4&page=10
I made some research on the web and found this link for instance: SEO friendly url using php
I like the idea of using FallbackResource as suggested in this post, and I tried however, while I don't understand the mechanism fully, I came to the conclusion that it only works if the file we want to access in the URL is not on the file system. So if you type www.test.com/test/toto and that the file toto doesn't exist then yow will be redirected to whatever FallbackResource points to. The problem with this approach is that it doesn't seem to work for paths such as:
www.test.com/folder/folder-1/folder-2
Because it seems like this considered as a series of sub-directories rather than a missing file. So I get an Error 500 in that case when FallbackResource is used (I can't really explain whether this is the right reason, but this is the only one I could come up with on my own. I asked on Stackoverflow but no answer so far: FallbackResource works for some pages but not others).
What I need is to "decompose" the URL so that I can look at the right information in the database. For example find the id of the book 34, and find in the database a page 10 which belongs to chapter 4 of book 34. I know how to do that. I can also build the URL.
What I don't know, is what's the best way to actually redirect any URL such as www.test.com/f-1/AA/B-2/tmp/C04/ or whatever, to a page from which I can then use the url path to extract the data from the database and display it on the page?
It seems like using a mechanism to catch missing pages (404) is not a good approach. I am also aware of the possibility of using RewriteRule but it seems like FallbackResource was said to be a better choice. However I can't get it to work in a generic fashion (maybe someone can tell me how, or what I am doing wrong?).
CMS are using SEO friendly URLs all the time, so there must be a "standard" way of doing this, and one that works in all cases (not like FallbackResource which seems limited).
It's the only part of my project which is not working yet, and because of this I am stuck while being close to the result. It's very frustrating. Any help would be greatly appreciated.