简体   繁体   English

请求的资源上不存在“Access-Control-Allow-Origin”标头”

[英]No 'Access-Control-Allow-Origin' header is present on the requested resource"

I have URL rewrite mode enabled for my localhost (apache) server well.我为我的 localhost (apache) 服务器启用了 URL 重写模式。 But as soon as I try to get access the remote URL via my localhost.但是一旦我尝试通过我的本地主机访问远程 URL。 it prompts error as:它提示错误为:

"Internal Server Error" or sometime "Not Found" 

and if I make little change (by removing [P]) in my htaccess file then it's showing the expected URL at console log but still it prompts error as -如果我在我的 htaccess 文件中做很少的更改(通过删除 [P]),那么它会在控制台日志中显示预期的 URL,但它仍然提示错误 -

" No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://localhost:8080' is therefore not allowed access."

My .htaccess file is as:我的 .htaccess 文件如下:

 <IfModule mod_rewrite.c>
  RewriteEngine on 
  RewriteCond  %{SERVER_PORT} !^8080$
  RewriteRule ^(.*) http://%{SERVER_NAME}:8080%{REQUEST_URI} [P]
  RewriteRule ^(.*) http://<Remote_ip_address>:<port_no>%{REQUEST_URI} [P]
 </IfModule>

Any suggestion would be highly appreciated !!任何建议将不胜感激!

This is an intentional security feature (the Same-origin policy ).这是一个有意的安全功能(同源策略)。 You need to enable CORS (Cross-Origin Resource Sharing) on the destination server (not in your .htaccess file here, but on Remote_ip_address ).您需要在目标服务器上启用 CORS(跨源资源共享)(不是在此处的.htaccess文件中,而是在Remote_ip_address )。 Here are a few resources:以下是一些资源:

This solution below works for me in the vhost file located there :下面的解决方案在位于那里的 vhost 文件中对我有用:

/etc/httpd/conf.d/vhosts/xxxx.conf /etc/httpd/conf.d/vhosts/xxxx.conf

SetEnvIf Origin "^http(s)?://(.+\.)?(yourdomain\.com|otherdomain\.com)$" origin_is=$0
Header set Access-Control-Allow-Origin %{origin_is}e env=origin_is
Header set Access-Control-Allow-Credentials "true"
Header always set Access-Control-Allow-Headers "Authorization"
Header always set Access-Control-Allow-Methods "GET"

DO NOT FORGET不要忘记

  • to change yourdomain.com|otherdomain.com更改yourdomain.com|otherdomain.com
  • To add/modify the correct Access-Control-Allow-Methods GET, PUT,PUATCH, DELETE, POST添加/修改正确的 Access-Control-Allow-Methods GET、PUT、PUATCH、DELETE、POST

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CORS过滤器tomcat 7请求的资源上没有“Access-Control-Allow-Origin”标头 - CORS filter tomcat 7 No 'Access-Control-Allow-Origin' header is present on the requested resource Laravel Apache Project中的请求资源上没有&#39;Access-Control-Allow-Origin&#39;标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource in Laravel Apache Project Wampserver XMLHttpRequest无法加载所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Wampserver XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource 错误:所请求的资源上没有“ Access-Control-Allow-Origin”标头。 即使包括CORS支持 - Error: No 'Access-Control-Allow-Origin' header is present on the requested resource. even after including the CORS support Apache Tomcat请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Apache Tomcat No 'Access-Control-Allow-Origin' header is present on the requested resource 带有Apache的&#39;Access-Control-Allow-Origin&#39;标头 - The 'Access-Control-Allow-Origin' header with apache Access-Control-Allow-Origin标头 - Access-Control-Allow-Origin header Apache否&#39;Access-Control-Allow-Origin&#39;标头 - Apache No 'Access-Control-Allow-Origin' header 错误:不存在“ Access-Control-Allow-Origin”标头。 即使我添加了它 - Error: No 'Access-Control-Allow-Origin' header is present. Even though I have added it XMLHttpRequest无法加载。 不存在“ Access-Control-Allow-Origin”标头。 (阿帕奇/ jQuery的/ AJAX) - XMLHttpRequest cannot load. No 'Access-Control-Allow-Origin' header is present. (Apache/jQuery/AJAX)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM