[英]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不要忘记
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.