mk1*_*k12 3 url website webserver
某些网站,无论您在哪个页面上,始终只在地址栏中显示其域名,而不显示其他任何内容。
许多显示文件夹,例如https://superuser.com/questions/ask,但不显示实际文件,就像http://domain.tld/folder/file.extension.
两者是如何实现的?
这是因为对 URL 的实际含义存在一些误解,这可能得益于静态 .HTML 文件和 PHP 脚本的时代。
传统上,TLD 之后的所有内容都是指向特定文件的指针。假设博客文章位于example.com/blog/2009/oct/18/what-have-we-come-to。如果不使用花哨的技术,这将意味着有一个名为 blog 的2009文件夹,其中有一个文件夹,每个月都有一个文件夹,而在这些文件夹中还有一个 ANOTHER 文件夹,每个月的每一天。显然,这很快就会变得非常复杂。
这就是为什么 Web 服务器(例如 Apache)和编程语言(例如 PHP)发明了URL 重写。这样做是将上述 URL 转换为更易于管理的内容,例如example.com/blog/articles.php?id=423. 在这里,articles.php脚本将使用提供的帖子 ID 查找适用的帖子,然后显示帖子,但用户仍会看到 URL 为example.com/blog/2009/oct/18/what-have-we-come-to。
另一种方法只是完全废弃所有这些。TLD 之后的所有内容(在本例中为/questions/56772/website-url-hiding-hiding-file)只是指向内容的指针,不一定是文件。一些网站,例如超级用户,使用 MVC(模型-视图-控制器)方法构建的。通常,这涉及网站的 URL 列表,并将它们映射到适用的功能和代码以显示该页面。例如,超级用户可能看起来像这样1:
'superuser.com/' > displayFrontPage()
'superuser.com/questions/' > displayQuestionsList(sorted=default)
'superuser.com/questions/<QuestionID>/<QuestionID>' > displayQuestion(question= QuestionID)
Run Code Online (Sandbox Code Playgroud)
这通常会单独放置在一个文件中。我常见的布局可能是:
superuser/
controller.aspx (which contains the list of URLs and points to a view in views.aspx)
views.aspx (which contains all the code for the superuser, such as displayFrontPage() and displayQuestion(question= QuestionID))
models.aspx (which contains information about the table in the database.)
Run Code Online (Sandbox Code Playgroud)
1请记住,我不知道控制器如何为 ASP MVC 工作(我更像是一个 Django 人),所以这可能不是那么准确。这只是一个例子
| 归档时间: |
|
| 查看次数: |
1856 次 |
| 最近记录: |