Search code examples
phpuriandroid-contentprovider

PHP URIs not physically corresponding to path in file system


I have a question about URIs. Till last week I though, that parts of URI goin' after host always specify real path in file system. But then I get to know with content providers when developing an android app and found out that ID 231 in sample URI don't physically correspond to a folder.

scheme://example.com/records/231/edit

When a PHP application uses URIs like this one above, I'm sure that they don't have a single folder for every record on their server. So my question is how to achieve functionality like this with PHP, I have no idea.


Solution

  • A webserver receives an URL and interprets it in some way. The most usual and canonical way is to have a root directory for each domain and everything after the domain name (like /records/231/edit) is mapped to a file in that root directory.

    However, the interpretation of that is really up to the webserver (and how it is configured). Apache webservers allow URL rewriting, that internally rewrites any URL / URI to another URL/URI. Almost every webserver provides this kind or a similar kind of rewriting. The most common one is to map everything to some index.php (except for URIs that actually exist) and the index.php looks into $_SERVER['SCRIPT_NAME'] or something to find, what uri is called and handles the request appropriately.

    The reason to do this / the concept is: Semantic URL