No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access

后端 未结 11 1861
醉话见心
醉话见心 2020-11-22 14:27

I\'m using .htaccess to rewrite urls and I used html base tag in order to make it work.

Now, when I try to make an ajax request I get the following error:

11条回答
  •  無奈伤痛
    2020-11-22 14:31

    Solved with below entry in httpd.conf

    #CORS Issue
    Header set X-Content-Type-Options "nosniff"
    Header always set Access-Control-Max-Age 1728000
    Header always set Access-Control-Allow-Origin: "*"
    Header always set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT,PATCH"
    Header always set Access-Control-Allow-Headers: "DNT,X-CustomHeader,Keep-Alive,Content-Type,Origin,Authentication,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control"
    Header always set Access-Control-Allow-Credentials true
    
    #CORS REWRITE
    RewriteEngine On                  
    RewriteCond %{REQUEST_METHOD} OPTIONS 
    #RewriteRule ^(.*)$ $1 [R=200,L]
    RewriteRule ^(.*)$ $1 [R=200,L,E=HTTP_ORIGIN:%{HTTP:ORIGIN}]]
    

提交回复
热议问题