Enabling Cross-Origin Resource Sharing (CORS)
Cross-Origin Resource Sharing (CORS) allows web browsers to request resources from a different domain than the one the web application is running on. For example, an application on https://example.com can request resources from https://example-2.com if CORS is properly enabled.
Important Considerations
-
If using HTTPS, ensure all servers have valid and trusted SSL certificates.
-
Some browsers, like Firefox, will block cross-origin requests if the SSL certificate is invalid, even if CORS is enabled correctly.
How to Enable CORS
-
Open or create the
.htaccessfile in the directory where you want to allow cross-origin requests. -
Add the following line to the
.htaccessfile:
Header set Access-Control-Allow-Origin "*"
-
Using
"*"allows requests from any origin. -
For more restrictive access, replace
"*"with the specific domain(s) you want to allow.
More Information
For detailed guidance on CORS, visit MDN Web Docs: CORS.