I am trying to figure out how to design an application which has documents(in html-format)/content in a directory structure. What I want is that the URL should decide which document that should be presented. E.g. http://www.mydomain.com/docs/read_this should in some way help me present content named “read_this”.
I also want the possibility for the users to make a full search of the docs. First, I had the intent of storing all docs in MySQL and user the built in support for full search. But I got stuck in how to solve the URI vs. content problem. Since it should be possible to create or edit content I though that storing it in the database would make it easier than putting it in files as well.
This is the normal way of doing it, many sites implement it like this. Still, I cannot find anything about how to solve it. Perhaps the words used for googling is to similar to other info; document, directory, structure, content, URI, etc…
I am using Apache/httpd and PHP on CentOS 6.2.
What is the approach for solving above mentioned problem?
You’re almost creating a REST interface, but since you’re wanting to serve the documents directly, it’s not quite.
I’d suggest a structure like:
http://example.com/docs/: Root level of your application (shows some info about the apphttp://example.com/docs/view/read_this: Show the document named “read_this”http://example.com/docs/search/keyword: Show a list of documents that contain the keyword “keyword”Adding the “view” and “search” parent “folders” prevents collision; if you just had
http://example.com/docs/read_thisas the document view schema (and left the search schema as-is), you could never have a document namedsearchsince that would collide with the specialsearchterm. You also mentioned editing, which could be done with ahttp://example.com/edit/read_thisschema.In order to make all these URIs resolve, you’d need to use Mod_Rewrite in your Apache config to point them at your PHP script.
EDIT: Here’s the
.htaccessand PHP link needed.htaccess:
This goes in the root of your
docsfolder, alongsideindex.php:This technically means that people could enter the URL
http://example.com/docs/view/read_thisorhttp://example.com/docs/index.php?action=view&target=read_thisand get the same resultindex.php: