繁体   English   中英

您如何编写网络脚本来处理格式为example.com/data/234而不是example.com/data.php?id=234的网址?

[英]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?

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

  • 如何设置脚本来做到这一点?
  • example.com/student/32053不会从“ student”的“ 32053”子目录中加载index。*吗?

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

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

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

让我知道您是否需要类似的Microsoft IIS示例。

暂无
暂无

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

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