![](/img/trans.png)
[英]No 'Access-Control-Allow-Origin' header is present on the requested resource with or without www
[英]Access Control Allow Origin with and without www
我用以下 header 構建了一個 php API:
header("Access-Control-Allow-Origin: https://my-domain.de");
這樣,我只能從https://my-domain.de
訪問 api,但不能從https://www.my-domain.de
我得到:
Origin https://www.my-domain.de is not allowed by Access-Control-Allow-Origin.
[Error] XMLHttpRequest cannot load https://my-domain.de/checkin/api/generateUser.php due to access control checks.
我怎樣才能使它同時適用於:www 和沒有 www?
您可以添加另一行:
header("Access-Control-Allow-Origin: https://my-domain.de");
header("Access-Control-Allow-Origin: https://www.my-domain.de");
PHP 不支持通配符標頭,您要么支持所有域:
header("Access-Control-Allow-Origin: *");
或具體如上
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.