I'm working with an apache server, and I'd like to add headers conditionally.
If the URI matches a certain regex, I'd like to add the header Access-Control-Allow-Origin: *
. What is a good way to do this?
What I've tried so far:
I added code called by the request handler, using
apr_table_add(rq->headers_out, "Access-Control-Allow-Origin", "*")
. But it seems like Apache strips the header before sending the response whenever the headerContent-Type: application/x-javascript
is also set. Is this the wrong way to do it? Why would Apache strip the header?I've heard mod_headers suggested. Does mod_headers have the capability to place headers based on regex matching with the request URI?
but this works only if located in the configuration. Placing it into .htaccess won't help.
This should also work (mod_rewrite is required):
where
^/en/foo.*$
a regex which is matched against request URL