使用urlrewritefilter设置从请求到响应头的原点或引用值 [英] Setting origin or referer value which from request to the response-header using urlrewritefilter
本文介绍了使用urlrewritefilter设置从请求到响应头的原点或引用值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用tuckey url重写过滤器xml文件在响应标头中设置原始值或参考值.
How to set origin value or referer value in a response-header using tuckey url rewrite filter xml file.
直接在set标记中访问%{origin}
无效,但在条件标记中无效.
Accessing %{origin}
directly in the set tag is not working but not working in condition tag.
下面是我尝试的示例.
<rule enabled="true" last="false" match-type="regex">
<name>Enabling CORS Headers</name>
<from>^/path/someMorePath.*$</from>
<condition name="origin" operator="equal">http://www.testsite.com</condition> <!-- would like to write some regex to match a set of sites and if matched, then set the same origin as response -->
<set type="response-header" name="Access-Control-Allow-Origin">%{origin}</set>
<set type="response-header" name="Access-Control-Allow-Credentials">true</set>
</rule>
推荐答案
全面了解了tuckey api的urlrewritefilter后,解决方案是使用正则表达式.
After having an complete understanding on the urlrewritefilter of tuckey api, the solution is to have a regular expression.
<rule enabled="true" match-type="regex">
<name>Enabling CORS Headers</name>
<from>^/path/someMorePath.*$</from>
<condition name="origin" operator="equal">([a-z.\/\/0-9]+)</condition>
<set type="response-header" name="Access-Control-Allow-Origin">%1</set>
<set type="response-header" name="Access-Control-Allow-Credentials">true</set>
</rule>
因此,这里在条件标签中使用正则表达式,然后在正则表达式中使用反向引用作为响应头中的变量
So, here using the regular expression in the condition tag and then using the back references in the regular expression as the variables in the response header
这篇关于使用urlrewritefilter设置从请求到响应头的原点或引用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文