简体   繁体   English

将请求中的 Origin 添加到响应中的 Access-Control-Allow-Origin 标头

[英]Add the Origin from the requests to the Access-Control-Allow-Origin header in the response

I'd like to allow all origins to fetch resources from my apache server.我想允许所有来源从我的 apache 服务器获取资源。

Instead of adding:而不是添加:

Access-Control-Allow-Origin: *

I would like my server to craft a special response with :我希望我的服务器制作一个特殊的响应:

Access-Control-Allow-Origin: <the value of the Origin received in the request>

Is there something I can add to httpd.conf to achieve this ?有什么我可以添加到 httpd.conf 来实现的吗?

Seems it can be achieved by adding those two lines:似乎可以通过添加这两行来实现:

SetEnvIf Origin ".*\S.*" ORIGIN=$0
Header always set Access-Control-Allow-Origin %{ORIGIN}e env=ORIGIN

The regex pretty much means anything except newline, tab, and space, so as long as the Origin is not empty add it to the response header.正则表达式几乎意味着除换行符、制表符和空格之外的任何内容,因此只要 Origin 不为空,请将其添加到响应标头中。

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

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