# Enabling Cross-Origin Resource Sharing (CORS)

> Enable Cross-Origin Resource Sharing (CORS) with headers so web apps on other domains can request your resources.

Source: https://helpcenter.ruachost.com/developers/guides/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

1. Open or create the `.htaccess` file in the directory where you want to allow cross-origin requests.
2. Add the following line to the `.htaccess` file:

```
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](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).
