【问题标题】:How do I use Apache mod_rewrite rewritecond with POST parameters?如何将 Apache mod_rewrite rewritecond 与 POST 参数一起使用?
【发布时间】:2013-12-03 19:17:32
【问题描述】:

我知道我可以在 rewritecond 中检查 GET 查询字符串参数,如下所示:

RewriteCond %{REQUEST_URI} ^/somepath/somepath
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} try=3
RewriteCond %{QUERY_STRING} name=([^&]*)
RewriteRule ^/somepath/somepath(.*) /otherpath/otherpath?name=%1 [R]

如何检查请求正文中的 POST 参数?我听说 mod_security 可以做到,但我没有找到任何示例说明如何将 mod_security 与 mod_rewrite 结合使用,如上面的示例。

我打算使用这样的东西来处理 POST:

RewriteCond %{REQUEST_URI} ^/somepath/somepath
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^/somepath/somepath(.*) /otherpath/otherpath [PT]

...除了我需要一个 RewriteCond 来检查 POST 参数以查看是否“try=3”。

modsecurity 能否检查请求正文并将检查结果加载到环境变量中?这会工作......

【问题讨论】:

  • 我想你从来没有想过这个问题,是吗?我面临着非常相似的情况。
  • 没有使用 Apache HTTP 服务器的解决方案。就我而言,Apache 是后端 weblogic 服务器的反向代理。我最终编写了一个托管在 weblogic 中的 java servlet 来处理 POST 的重定向。
  • 谢谢。我最终需要做类似的事情。构建了一个小 node.js 应用程序作为我的反向代理。不像我希望的那样干净,但它确实有效。

标签: apache mod-rewrite mod-security


【解决方案1】:

您无法使用 mod_rewrite 检查请求正文。

如果您可以这样做,您可能必须将 POST 请求重写为脚本。如果您重定向它们,浏览器并不总是会重新发送 POST 数据。

【讨论】:

  • 谢谢乔恩。我更新了我的问题,显示我打算如何处理 POST - 使用 PT 而不是 R。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多