Page 1 of 1

Cross-Origin-Resource-Sharing with Apache for a single file

PostPosted: 20. September 2014 22:52
by hansa
Hi,

I have an Appache Server (2.4) running on my machine, and would like to enable CORS for a certain file.

According to http://jerome.co.za/enabling-cross-origin-resource-sharing-aka-cors-in-apache/ I need to do something like the following i my httpd.conf:

Code: Select all
<Files "C:/xampp/htdocs/some/path/file.txt">
    Header set Access-Control-Allow-Origin "*"
</Files>


I have added this to my httpd.conf file, saved it, and restarted the server.

However, when trying to get this resource via ajax from a different network, I still get this issue:

XMLHttpRequest cannot load http://SERVERDNS.com/some/path/file.txt. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.


How can I fix this? I am not sure if I put the tag in the correct place in httpd.conf, and also I am not sure about whether the Setting itself is done correctly.

I am running this server on a Windows Server 2012 machine on the Amazon Web Services EC2 cloud.

Can anyone shed some light onto this for me?

Thanks, best regards,

Chris

Re: Cross-Origin-Resource-Sharing with Apache for a single f

PostPosted: 21. September 2014 11:44
by Nobbie
hansa wrote:According to http://jerome.co.za/enabling-cross-orig ... in-apache/ I need to do something like the following i my httpd.conf:

Code: Select all
<Files "C:/xampp/htdocs/some/path/file.txt">
    Header set Access-Control-Allow-Origin "*"
</Files>


You have to put these lines not SOMEWHERE in httpd.conf, it must be inside the VirtualHost of your SERVERDNS.com