Apache, LocationMatch: match query string

為{幸葍}努か 提交于 2021-01-02 07:21:51

问题


How can I match a query string using LocationMatch with apache?

<LocationMatch "/index.php\?a=b.*">
// ...

... won't work unfortunately.


回答1:


Looks like you can't include query strings in Location/LocationMatch.

From the Apache Docs:

For all origin (non-proxy) requests, the URL to be matched is a URL-path of the form /path/. No scheme, hostname, port, or query string may be included. For proxy requests, the URL to be matched is of the form scheme://servername/path, and you must include the prefix.




回答2:


https://serverfault.com/questions/848320/can-locationmatch-regex-match-query-string-portion

Actually it's possible since Apache 2.4 (or less) using the tag as follow :

<LocationMatch "/test/upload.js">
        <If "%{QUERY_STRING} =~ /query=test/">
                ..
                'Your directives'
                ..
       </If>
</LocationMatch>

In this configuration directives will be applied only in the case the URL is under the form "/test/upload.js" and contains the query "query=test".



来源:https://stackoverflow.com/questions/2019594/apache-locationmatch-match-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!