是否可以使用rack-rewrite仅重写POST请求?

发布于 2024-10-10 04:45:05 字数 149 浏览 1 评论 0原文

就是这样。我只需要重定向 POST 请求。比如:

rewrite /.*/, '/universal_POST_handler', :if => (something_cool_goes_here)

这可能吗?

That's it. I need to redirect just the POST requests. Something like:

rewrite /.*/, '/universal_POST_handler', :if => (something_cool_goes_here)

Is it possible?

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

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

发布评论

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

评论(2

心碎无痕… 2024-10-17 04:45:05

具有路由的应用程序中重写器的目的是将旧 URL 重写为更新的 URL。旧版 URL 是受支持且外部用户开始依赖的 URL,但由于应用程序的体系结构已更改而不再受支持。

您应该使用路由器。

post '*path' => 'actions#universal',
  :constraints => FancyConstraint.new

The purpose of a rewriter in an application that has routing is to rewrite legacy URLs to more current URLs. Legacy URLs are URLs that were supported and that external users have come to depend on but that are no longer supported because the architecture of the application has changed.

You should use the router instead.

post '*path' => 'actions#universal',
  :constraints => FancyConstraint.new
清醇 2024-10-17 04:45:05

README

使用:method 选项您可以通过给定请求的 HTTP 方法来限制规则的匹配。

重定向 GET 一种方式

r301 "/players", "/current_players", :method => :get

并以另一种方式重定向 POST

r302 "/players", "/no_longer_available.html?message=No&longer&supported", :method => :发布

From the README:

Using the :method option you can restrict the matching of a rule by the HTTP method of a given request.

redirect GETs one way

r301 "/players", "/current_players", :method => :get

and redirect POSTs another way

r302 "/players", "/no_longer_available.html?message=No&longer&supported", :method => :post

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