1
    <FilesMatch "\.(json|txt)$" >
       SetEnvIf Origin "http(s)?://(www\.)?(sub.domain.com|sub2.domain.com|www.domain2.com)$" AccessControlAllowOrigin=$0$1
       Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
       Header set Access-Control-Allow-Credentials true
       Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
    </FilesMatch>

If I use middle block on it's own (without FilesMatch) then it works and i can make my request. If I test my FilesMatch by putting Deny from all inside it then it clearly works as well. But put both of them together and I can't make the request. It seems to go thrum, but without credentials and throws out Access-Control-Allow-Origin warning.

somerandomusername
  • 1,993
  • 4
  • 23
  • 55
  • refer this post with success message with your same code http://stackoverflow.com/questions/20673882/handle-multiple-domains-with-access-control-allow-origin-header-in-apache/22331450#22331450 – Dickens A S Jun 30 '15 at 15:54
  • @ZigmaEmpire I don't have problem with setting Access-Control-Allow-Origin, i can't do it together with FilesMatch, it just doesn't work. – somerandomusername Jun 30 '15 at 15:58

1 Answers1

1

Try to put your \. inside the brackets

<FilesMatch "(?<!\.json|\.txt)$">

Try to enclose your expression as string, like "%{AccessControlAllowOrigin}e"

<FilesMatch "(?<!\.json|\.txt)$" >
       SetEnvIf Origin "http(s)?://(www\.)?(sub.domain.com|sub2.domain.com|www.domain2.com)$" AccessControlAllowOrigin=$0$1
       Header add Access-Control-Allow-Origin "%{AccessControlAllowOrigin}e" env=AccessControlAllowOrigin
       Header set Access-Control-Allow-Credentials true
       Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</FilesMatch>
Dickens A S
  • 3,824
  • 2
  • 22
  • 45