是否可以使用rack-rewrite仅重写POST请求?
就是这样。我只需要重定向 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
具有路由的应用程序中重写器的目的是将旧 URL 重写为更新的 URL。旧版 URL 是受支持且外部用户开始依赖的 URL,但由于应用程序的体系结构已更改而不再受支持。
您应该使用路由器。
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.
从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