简体   繁体   English

PHP URI物理上不对应于文件系统中的路径

[英]PHP URIs not physically corresponding to path in file system

I have a question about URIs. 我有一个关于URI的问题。 Till last week I though, that parts of URI goin' after host always specify real path in file system. 但是直到上周,主机之后的URI部分始终在文件系统中指定真实路径。 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. 但是后来我在开发一个Android应用程序时与内容提供商了解了一下,发现示例URI中的ID 231在物理上并不对应于一个文件夹。

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. 当PHP应用程序使用上面类似的URI时,我确定它们的服务器上的每个记录都没有一个文件夹。 So my question is how to achieve functionality like this with PHP, I have no idea. 所以我的问题是如何用PHP实现这样的功能,我不知道。

A webserver receives an URL and interprets it in some way. Web服务器接收URL并以某种方式对其进行解释。 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. 最常用的规范方法是为每个域都有一个根目录,并将域名(例如/records/231/edit )之后的所有内容都映射到该根目录中的文件。

However, the interpretation of that is really up to the webserver (and how it is configured). 但是,对它的解释实际上取决于Web服务器(以及它的配置方式)。 Apache webservers allow URL rewriting, that internally rewrites any URL / URI to another URL/URI. Apache Web服务器允许URL重写,该URL在内部将任何URL / URI重写为另一个URL / URI。 Almost every webserver provides this kind or a similar kind of rewriting. 几乎每个Web服务器都提供这种或类似的重写。 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. 最常见的方法是将所有内容都映射到某个index.php (实际存在的URI除外),而index.php查找$_SERVER['SCRIPT_NAME']或要查找的内容,即调用uri并适当地处理请求。

The reason to do this / the concept is: Semantic URL 这样做的原因/概念是: 语义URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM