Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am in the progress of migrating an old banner system to a new one and in doing so I want to rewrite the old banner system's URL's to the new one. I load my banners via an AJAX request, and therefore I require the Access-Control-Allow-Origin to be set to *.

I have the following VirtualHost configuration:

<VirtualHost *:80>

    # we want to allow XMLHTTPRequests
    Header set Access-Control-Allow-Origin "*"

    RewriteEngine on
    RewriteMap bannersOldToNew txt:/home/user/

    # check whether a zoneid exists in the query string
    RewriteCond %{QUERY_STRING} ^(.*)zoneid=([1-9][0-9]*)(.*)
    # make sure the requested banner has been mapped
    RewriteCond ${bannersOldToNew:%2|NOTFOUND} !=NOTFOUND
    # rewrite to
    RewriteRule ^/ads/.*${bannersOldToNew:%2}%3 [R]
    # else 404 or something

    ErrorLog ${APACHE_LOG_DIR}/

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/ combined


My map file, /home/user/, contains something like:

# oldId newId
140 11
141 12
142 13

Based on the above configuration I was expecting the following:

GET /ads/ajs.php?zoneid=140 HTTP/1.1

HTTP/1.1 302 Found
Access-Control-Allow-Origin: *

But instead I get the following:

GET /ads/ajs.php?zoneid=140 HTTP/1.1

HTTP/1.1 302 Found

Note the missing Access-Control-Allow-Origin header, this means the XMLHttpRequest is denied and the banner is not displayed. Any suggestions on how to fix this in Apache?

share|improve this question

migrated from Apr 11 '12 at 16:43

This question came from our site for professional and enthusiast programmers.

up vote 0 down vote accepted

I found a solution to this problem, apparently Apache Header set only applies to 2xx status codes (assumption based on To get the access control header to work in my configuration I had to type Header always set:

<VirtualHost *:80>

    # we want to allow XMLHTTPRequests
    Header always set Access-Control-Allow-Origin "*"


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.