如何编写web脚本来处理example.com/data/234而不是example.com/data.php形式的UR


How do you write a web script to deal with urls of the form example.com/data/234 rather than example.com/data.php?id=234?

我习惯于在PHP脚本中使用$_POST$_GET数组。我正在尝试学习Backbone(特别是Backbone.sync函数),显然它假设您将设置服务器,以便example.com/student/32053检索id为32053的学生。

  • 我该如何设置我的脚本来执行此操作
  • example.com/student/32053是否从"student"的"32053"子目录加载索引.*

在Apache服务器上,使用mod_rewrite模块。在.htaccess文件中,只需指定一个简单的规则,如:

^data/('d+)$ data.php?id=$1 [L]

这样,在调用example.com/data/100时,apache将在内部调用example.com/data.php?id=100

如果您需要类似的Microsoft IIS示例,请告诉我。