Combining URL mapping and Access-Control-Allow-Origin: *
Posted
by
ksangers
on Server Fault
See other posts from Server Fault
or by ksangers
Published on 2012-04-11T14:44:48Z
Indexed on
2012/04/11
17:32 UTC
Read the original article
Hit count: 368
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>
ServerAdmin [email protected]
ServerName banner.studenten.net
# we want to allow XMLHTTPRequests
Header set Access-Control-Allow-Origin "*"
RewriteEngine on
RewriteMap bannersOldToNew txt:/home/user/banner.studenten.net/banner-studenten-net-to-ads-all4students-nl-map
# 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 ads.all4students.nl
RewriteRule ^/ads/.* http://ads.all4students.nl/delivery/ajs.php?%1zoneid=${bannersOldToNew:%2}%3 [R]
# else 404 or something
ErrorLog ${APACHE_LOG_DIR}/banner.studenten.net-error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/banner.studenten.net-access.log combined
</VirtualHost>
My map file, /home/user/banner.studenten.net/banner-studenten-net-to-ads-all4students-nl-map
, 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
Host: banner.studenten.net
HTTP/1.1 302 Found
...
Access-Control-Allow-Origin: *
Location: http://ads.all4students.nl/delivery/ajs.php?zoneid=11
But instead I get the following:
GET /ads/ajs.php?zoneid=140 HTTP/1.1
Host: banner.studenten.net
HTTP/1.1 302 Found
...
Location: http://ads.all4students.nl/delivery/ajs.php?zoneid=11
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?
© Server Fault or respective owner