Multiple Access-Control-Allow-Origin Domains

4

I have a page that serves some data in JSON format based on the data received from the database, but I need to release access so that the mobile version can also get such data, how can I put more than one domain in Access-Control- Origin of htaccess?

I tried the code below but it did not work

<IfModule mod_headers.c>
    SetEnvIf Origin "http(s)?://(www\.)?(dominio.com|m.dominio.com)$" AccessControlAllowOrigin=$0
    Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
</IfModule>
    
asked by anonymous 02.02.2017 / 14:07

2 answers

2

Try this:

<FilesMatch "\.json$">
    <IfModule mod_headers.c>
        SetEnvIf Origin "http(s)?://(www\.)?(dominio.com|m.dominio.com)$" AccessControlAllowOrigin=$0
        Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
    </IfModule>
</FilesMatch>

Updated:

Or try using addHeader ,

response.addHeader("Access-Control-Allow-Origin", "*");

  

* serves to give access to all domains

To give access to specific domains use:

  

response.addHeader("Access-Control-Allow-Origin", "http://www.example.com");

    
02.02.2017 / 14:38
-2

Maybe it's not the answer you want, but would not it be possible to use JSONP? Maybe it's simpler than trying to tinker with the htacess for different cases.

    
07.02.2017 / 16:00