带有 php 的 Ghost 目录/文件?
我想知道 WordPress 和其他随机论坛和网站(例如 facebook)如何创建类似的虚拟目录?例如,博客可能有 http://www.joesblog.com/2010/11/12/this-is-my-post.php
该文件和目录资源确实存在吗?另外,例如 Facebook 是如何拥有 http://www.facebook.com/-usernamehere-
的?这是一个物理目录,还是只是一个脚本技巧?我怎样才能用 PHP 做到这一点?
I was wondering how Wordpress and other random forums and sites, like facebook, create like phantom directories? Eg, a blog might have http://www.joesblog.com/2010/11/12/this-is-my-post.php
Does that file and directory resource actually exist? Also, how does Facebook, for example, have like http://www.facebook.com/-usernamehere-
? Is that a physical directory, or is it simply a scripting trick? How can I do this with PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种功能通常是通过指示 Web 服务器将某些 URL 模式“链接”到特定控制器来实现的。
例如,请参阅 .htaccess。
编辑:这篇关于重写引擎的文章可能也会有所帮助。
所以不,实际上不存在目录。 Web 服务器接收对特定 URI 的请求,并将该请求重定向到委托控制器(例如,可以是 PHP 脚本),该控制器又根据用户请求的 URI 和操作返回结果。
PHP 当然可以处理这个问题,但需要指导 Web 服务器如何处理这些类型的请求。
如果您使用的是 apache,您可能需要查看一些mod_rewrite 教程 。
That kind of functionality is normally achieved by instructing the web server to "link" certain URL patterns to a specific controller.
See .htaccess, for example.
EDIT: This article on Rewrite engine might also help.
So no, no directories actually exist. The web server receives a request for a specific URI and redirects that request to a delegated controller (that can be a PHP script, for example) that in turn returns a result based on the URI and action requested by the user.
PHP can certainly handle this, but it's the web server that needs to be instructed on how to handle those types of request.
If you're using apache you might want to take a look at some mod_rewrite tutorials.