如何分配一个处理程序来处理任何 URL?

发布于 2024-08-06 03:02:16 字数 560 浏览 2 评论 0原文

我正在做一个具有 REST 架构的网站,我发现后者很难做到。 我希望能够处理如下 HTTP 请求:

GET /myapp/5445/ HTTP/1.1 ...

在理想的世界中,我会编写自己的服务器并自己处理所有 HTTP 请求,但我实际上想使用 CGI 或 PHP 来完成这个项目,并且我希望能够将这些 HTTP 请求映射到一个程序,该程序将决定无论这是否是有效的请求。

使用 REST 架构,GET /myapp/5445/ 可能意味着“给我资源 #5445。 PUT /myapp/5445/ 可能意味着“创建资源#5445”。

这个 URL 问题是阻止我发布杀手级应用程序的唯一因素! :) 也许不是,但谢谢你,

我目前正在使用 lighttpd 和 CGI​​。如果我能有一个 Apache 解决方案,我会很乐意切换。

顺便说一句,这个网站似乎有一种方法可以处理这些不存在的 URL,而无需调用错误 404 处理程序 http://pastebay.com/57208

I am doing a website with a REST architecture and I am finding the latter difficult to do.
I want to be able to handle HTTP Requests like these :

GET /myapp/5445/ HTTP/1.1
...

In an ideal world, I would code my own server and handle all the HTTP requests myself but I actually want to do this project with CGI or PHP and I want to be able to map these HTTP requests to a program that will decide wether or not it is a valid request.

With a REST Architecture, a GET /myapp/5445/ could mean "Give me resource #5445.
A PUT /myapp/5445/ could mean "Create resource #5445".

This URL problem is the only thing stopping me from releasing a killer app!! :) Maybe not but thank you

I am currently working with lighttpd and CGI. If I can have an Apache solution, I will gladly switch.

By the way, this website seems to have a way to handle these non-existing URLS without calling the Error 404 handler
http://pastebay.com/57208

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城仅有旧梦在 2024-08-13 03:02:16

使用 apache,您可以设置一个 .htaccess 文件,将所有请求转发到单个控制器脚本:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ controller.php [QSA,L]

在controller.php 中,您可以对 URL 执行任何操作。

With apache you can setup a .htaccess file to forward all requests to a single controller script:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ controller.php [QSA,L]

In controller.php you can do whatever you want with the URL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文