handle multiple domains with Access-Control-Allow-Origin header in Apache

后端 未结 8 891
独厮守ぢ
独厮守ぢ 2020-12-08 10:17

I want to configure apache for cross-domain access header. I have tried multiple combination as suggested on number of threads on the forum. But its not working for me.

相关标签:
8条回答
  • 2020-12-08 10:38

    I am using this in my .htaccess file for allowing access to multiple domains

     <ifModule mod_headers.c>
        SetEnvIf Origin "http(s)?://(localhost:25120|domain.com|domain2.com)$" AccessControlAllowOrigin=$0
        Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
        Header always set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
     </ifModule>    
    
    0 讨论(0)
  • 2020-12-08 10:46

    For Apache 2.4, I have used SET command for the Apache web server to set Header dynamically.

    <IfModule mod_deflate.c>
      # CORS
      SetEnvIfNoCase Origin "http(s)?://(\w+\.)?(example.com|localhost)(:[0-9]+)?$" AccessControlAllowOrigin=$0
      Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
      Header set Access-Control-Allow-Credentials true
    </IfModule>
    

    ADD command didn't work for me.

    0 讨论(0)
提交回复
热议问题