I have one domain having mywebsite.com and there would be multiple subdomains like subdomain.mywebsite.com , subdomain1.mywebsite.com , subdomain2.mywebsite.com and so on.

In htaccess file I have added

<IfModule mod_headers.c>
   Header add Access-Control-Allow-Origin  "http://subdomain.mywebsite.com"  
   Header add Access-Control-Allow-Origin  "http://subdomain1.mywebsite.com"
   .... and so on it will be there.
   Header add Access-Control-Allow-Credentials true

When I add this code to htaccess then I don't get any CORS error but now I don't want any errors for all the subdomains as above. I need dynamic code for multiple subdomain. So i don't need to add these lines often and often.

1 Answer 1


SetEnvIf Origin "^(.*.example.com)$" ORIGIN_SUB_DOMAIN=$1

Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN

  • Do i need to insert subdomain name for ORIGIN_SUB_DOMAIN ?
    – Nilesh B
    Mar 10, 2017 at 6:55
  • Please provide some information about that so that it can helpful for future reference Mar 10, 2017 at 7:17
  • No need to insert subdomain name for ORIGIN_SUB_DOMAIN, try it in your development environment first. Mar 12, 2017 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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