Skip to content

Instantly share code, notes, and snippets.

@yommu
Forked from chales/cors-apache.cfg
Created March 8, 2017 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yommu/a60f35098a6c77e8f45ac18eb13bf047 to your computer and use it in GitHub Desktop.
Save yommu/a60f35098a6c77e8f45ac18eb13bf047 to your computer and use it in GitHub Desktop.
Apache directive for a CORS to be used in a vhost or htaccess
<IfModule mod_headers.c>
# Enter possible domains and a cathcall regex for the subdomain.
SetEnvIf Origin "^http(s)?://(.+\.)?(domain1\.com|domain2\.com|domain3\.com)$" AllowOrigin=$0
Header always set Access-Control-Allow-Origin "%{AllowOrigin}e" env=AllowOrigin
Header merge Vary "Origin"
Header always append Access-Control-Max-Age "1000"
Header always append Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Accept-Encoding, \
if-modified-since, pragma, cache-control"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
# Preflight: Add a rewrite to respond with a 200 SUCCESS on every OPTIONS request.
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment