Skip to content

Instantly share code, notes, and snippets.

@guiliredu
Last active July 20, 2016 14:16
Show Gist options
  • Save guiliredu/7f133a984411c370e847842ca8c8d72a to your computer and use it in GitHub Desktop.
Save guiliredu/7f133a984411c370e847842ca8c8d72a to your computer and use it in GitHub Desktop.
Configura CORS in .htaccess
<IfModule mod_rewrite.c>
Header add Access-Control-Allow-Origin: "domain.tld"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "X-Requested-With, Content-Type"
RewriteEngine on
RewriteBase /
</IfModule>
@guiliredu
Copy link
Author

guiliredu commented Jul 20, 2016

Some points:

  • In Access-Control-Allow-Origin make sure you just add the domains you want to enable access
  • AJAX send a X-Requested-With header that was added in the .htaccess Headers
  • If you use apache as a web server, check if the header module is enabled, if not install it sudo a2enmod headers and restart apache

More info in: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment