6

I added the following to a vhost config in MAMP PRO:

Header set Access-Control-Allow-Origin "*"

(this is the only thing in the 'Additional parameters for ' box)

Which works great, if I inspect the headers from simply loading an image from the vhost's domain.

What doesn't work so great is if I try to access a URL that results in a (correct) 404.. the header is no longer set.

Is this normal? It doesn't seem normal. Why would Apache (or mamp) decide to ignore my 'Header set' directive just because there's a 404?

Request headers from loading an image:

Host: redacted.dev
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

Response headers from loading an image:

Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Connection: Keep-Alive
Content-Length: 18575
Content-Type: image/jpeg
Date: Wed, 18 Feb 2015 13:27:25 GMT
Etag: "81-488f-50f376cb56b40"
Keep-Alive: timeout=5, max=100
Last-Modified: Mon, 16 Feb 2015 16:53:25 GMT
Server: Apache

Request headers from trying to access something that isn't there:

Host: redacted.dev
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/35.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive

Response headers from trying to access something that isn't there:

Connection: Keep-Alive
Content-Length: 251
Content-Type: text/html; charset=iso-8859-1
Date: Wed, 18 Feb 2015 13:28:50 GMT
Keep-Alive: timeout=5, max=100
Server: Apache

A bit lost on this one...

John Hunt
  • 4,265
  • 8
  • 45
  • 59
  • Why should that matter? The image won't be loaded one way or the other. – Tomáš Fejfar Feb 18 '15 at 14:17
  • Because ultimately I'm using ajax to test if the image is there or not.. if it 404's then I get the CORS error message in the console, it it does then everything is fine. I don't want peoples consoles filling up with CORS errors – John Hunt Feb 18 '15 at 14:19

1 Answers1

6

You need the "always" prefix...

Header always set Access-Control-Allow-Origin "*"
Martin
  • 770
  • 6
  • 22