隐藏页面扩展(如StackOverflow) [英] Hide Page Extensions (Like StackOverflow)

查看:87
本文介绍了隐藏页面扩展(如StackOverflow)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像stackoverflow一样隐藏页面扩展.以下是如何工作的?

I want to hide page extensions like stackoverflow does. How does the following work?

http://stackoverflow.com/tags/foo
http://stackoverflow.com/tags/bar

我见过很多这样做的网站,但我仍然不知道如何实现(我有一个LAMP堆栈).

I've seen a lot of sites that do this, but I still don't know how this is accomplished (I have a LAMP stack).

推荐答案

当Web服务器收到对URL的请求时,它必须决定如何处理它.经典方法是将URL的头部映射到文件系统中的目录,然后让URL的其余部分导航到文件系统中的文件.结果,URL具有文件扩展名.

When a web server gets a request for a URL, it has to decide how to handle it. The classic method was to map the head of the URL to a directory in the file system, then let the rest of the URL navigate to a file in the filesystem. As a result, URLs had file extensions.

但是不需要那样做,大多数新的Web框架不需要这样做.它们使程序员可以定义如何将URL映射到要运行的代码,因此不需要文件扩展名,因为没有单个文件可以提供响应.

But there's no need to do it that way, and most new web frameworks don't. They let the programmer define how to map a URL to code to run, so there's no need for file extensions, because there is no single file providing the response.

在您的示例中,没有包含文件"foo"和"bar"的"tags"目录. 标签" URL映射到使用该URL其余部分("foo"或"bar")作为针对标签数据数据库的查询中的参数的代码.

In your example, there isn't a "tags" directory containing files "foo" and "bar". The "tags" URL is mapped to code that uses the rest of the URL ("foo" or "bar") as a parameter in a query against the database of tag data.

这篇关于隐藏页面扩展(如StackOverflow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆