如果有404,则Apache不提供CORS头

时间:2015-02-18 13:31:52

标签: apache http cors vhosts

我在MAMP PRO的vhost配置中添加了以下内容:

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

(这是'附加参数'框中唯一的内容)

如果我只是从vhost的域中加载图像来检查标题,那么哪种方法很有效。

如果我尝试访问导致(正确)404的URL,那么效果不佳的事情就是不再设置标题。

这是正常的吗?这似乎不正常。为什么Apache(或mamp)决定忽略我的'Header set'指令只是因为有404?

请求标头加载图片:

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

加载图片的响应标头:

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

请求标头尝试访问不存在的内容:

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

尝试访问不存在的内容时的响应标头:

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

这一点有点失落......

1 个答案:

答案 0 :(得分:2)

你需要"总是"前缀...

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