1

I'm asking this here as a last resort after trying different things / asking google / reading http://httpd.apache.org/docs/2.2/

I have the following in my apache2.conf

# Allow cross domain fonts
RewriteCond %{REQUEST_URI} (ttf|otf|eot|woff|svg) [OR]
RewriteCond %{QUERY_STRING} (ttf|otf|eot|woff|svg)
RewriteRule .* - [E=crossdomain:true]

# Cross domain videoplayer config
RewriteRule ^/video/player/config.json - [E=crossdomain:1]

# Cross domain for fragments
RewriteCond %{QUERY_STRING} fragment=true
RewriteRule .* - [E=crossdomain:1]

# Set header
Header set Access-Control-Allow-Origin "*" ENV=crossdomain

All of that works nicely. Now, I wanted URLs such as the following to have the

Access-Control-Allow-Origin "*"

...header as well:

/video/player/sources.json?contentId=AVID20150102_0012&width=640&height=360

As you can tell, such a URL is almost identical to the one in the above line:

RewriteRule ^/video/player/config.json - [E=crossdomain:1]

With (maybe) an important difference - that one (config.json) doesn't use query strings and this one (sources.json) does.

I've tried adding different rules in order to apply the "crossdomain" environment variable to the sources.json URL, with no success. For example:

RewriteCond %{REQUEST_URI} ^/video/player/sources.json [NC]
RewriteCond %{QUERY_STRING} ^contentId=(.*)&width=(.*)&height=(.*)
RewriteRule .* - [E=crossdomain:1]

Which I think should actually be the correct one (but since it doesn't work clearly I'm wrong).

I THINK the problem might have to do with the %{REQUEST_URI} somehow, since when I use this:

RewriteCond %{QUERY_STRING} contentId
RewriteCond %{QUERY_STRING} width
RewriteCond %{QUERY_STRING} height
RewriteRule .* - [E=crossdomain:1]

...the desired header appears in the response's headers, although I don't want the header to be applied to everything that uses those query parameters, it would be a wrong thing to do.

1
  • Oh, and just in case someone asks (since the apache-2.2 tag suggests it), output for apache2ctl -S is: "VirtualHost configuration: Syntax OK" Mar 10, 2015 at 18:54

1 Answer 1

0
+50

You can accomplish this with the following condition:

RewriteCond  %{REQUEST_URI}  ^/video/player/sources.json$
RewriteCond  %{QUERY_STRING} !=""
RewriteRule  . - [E=crossdomain:1] 

YMMV and may require some tweaks to work with another rules, but this is the way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .