在我的同一个域名中没有“访问控制 - 允许 - 来源”但没有'www'

Not sure what i'm doing wrong in my htaccess or so, but when I access my website from http://example.org instead of http://www.example.org it throws this error:

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

how do i setup my htaccess or my server apache to avoid this problem?

www.example.com and example.com are different origins. To be the same origin, the complete hostname, the port and the scheme have to match.

You have three options:

  • Set up CORS to grant access from one to the other.
  • When doing Ajax, use relative URIs instead of absolute ones.
  • Pick one to be canonical and stop hosting your website off the other.

The last approach is probably the best.

  1. Change all your links to be relative or to point to example.com
  2. Set up HTTP 301 Redirects for everything on www.example.com to example.com