简体   繁体   English

如何在Apache HTTP服务器中基于请求URL进行过滤

[英]How to filter based on request URL in Apache HTTP server

I want to have a apache http server in between my application and client. 我想在我的应用程序和客户端之间安装一个Apache http服务器。

A query parameter has to be passed on accessing by client. 客户端访问时必须传递查询参数。 For example, if my client is running in http://myhost:myport/myapp then it has to be accessed only by passing the parameter myparam. 例如,如果我的客户端在http:// myhost:myport / myapp中运行,则只能通过传递参数myparam来对其进行访问。 Like http://myhost:myport/myapp?myparam=123 . 就像http:// myhost:myport / myapp?myparam = 123一样

So in my apache http server I want to filter the requests which does not contain the query parameter myparam. 因此,在我的Apache http服务器中,我想过滤不包含查询参数myparam的请求。

I tried using filters . 我尝试使用过滤器 It has some predefined filters but none of the filters satisfy my requirement. 它具有一些预定义的过滤器,但是没有一个过滤器可以满足我的要求。 I tried using mod_ext_filter . 我尝试使用mod_ext_filter But it seems the entire content being passed to my program, not the URL. 但是似乎所有内容都传递给了我的程序,而不是URL。 Since I need to filter based on the parameter present in URL I don't think it satisfy my requirement. 由于我需要根据URL中存在的参数进行过滤,因此我认为它不能满足我的要求。

Is there any http server module which can be be used to filter based on parameter being passed in URL? 是否有任何HTTP服务器模块可用于基于URL中传递的参数进行过滤?

EDIT 编辑

In addition, I need to get the value from query param and validate it as well. 此外,我还需要从查询参数中获取值并进行验证。 The validation is a REST service call 验证是一个REST服务调用

In 2.4 you can do something as simple as: 在2.4中,您可以执行以下操作:

<Location /myapp>
  Require expr %{QUERY_STRING} =~ /myparam/
</location>

You can probably do this with <if> and captures, but I don't know how you can get it to lookup a "map" of context root to query param. 您可能可以使用<if>和捕获来执行此操作,但是我不知道如何获取它来查找上下文根的“映射”以查询参数。

If you have many myapp->myparam pairs, you might want to go to old school mod_rewrite and store them in a txt-based rewritemap. 如果您有许多myapp-> myparam对,则可能要去老学校mod_rewrite并将它们存储在基于txt的rewritemap中。 Here is an example that has a couple of "interesting" rewrite tricks to accomplish what you described: 这是一个示例,其中包含一些“有趣的”重写技巧来完成您描述的内容:

RewriteMap foo txt:/tmp/rewrite.map
RewriteEngine ON
# Fancy way to check two variables are equal in a RewriteCond
RewriteCond %{QUERY_STRING},${foo:$1} !^([^,]+),\1
# grab the first segment
RewriteRule ^/([^/]+)/ - [F]

But (if as discussed later in comments) you need to retrieve the map from some kind of remote web service you will need to implement a C or Lua module inside of httpd. 但是(如后面的评论中所述),您需要从某种远程Web服务中检索地图,您将需要在httpd内实现C或Lua模块。 The difficult part there becomes retrieving the remote response, the other parts are trivial: 那里最困难的部分变成了检索远程响应,其他部分则微不足道:

You could write your own access_checker module that finds r->uri and r->args pretty easily. 您可以编写自己的access_checker模块,该模块很容易找到r-> uri和r-> args。 But you need your own http client to make the outgoing REST call -- there is no API for this in the core. 但是您需要自己的http客户端来进行传出的REST调用-核心中没有用于此的API。 – covener Aug 24 at 13:27 –盟友8月24日13:27

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

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