简体   繁体   中英

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.

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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