How to enable CORS on a cPanel account

There is several ways to enable CORS (Cross-Origin Resource Sharing). On a cPanel server / account you need to do it with htaccess inside the domain's account. You need to edit the htaccess file and add one of these three lines:

This is the riskiest as it allows all domain cross resource sharing:

Header set Access-Control-Allow-Origin "*"

The safest way is to choose the domain to cross share like this:

Header always set Access-Control-Allow-Origin "yourdomain.com"

Or you may need to add the mod headers module:

<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "yourdomain.com"
</IfModule>

We suggest trying it with the domain and * for testing purposes.

The other ways include adding PHP code in the WordPress functions.php, which we were not able to make work.

And you can add code in the SSL apache core, which we also were not able to make work.

If adding Header always set Access-Control-Allow-Origin "yourdomain.com" does not work, it's likely not a CORS issue.

  • cors, server, enable, htaccess, Cross-Origin Resource Sharing
  • 18 Users Found This Useful
Was this answer helpful?

Related Articles

How to flush your DNS cache

Your home computer creates a cache for all DNS settings. It does this to save time each time you...

What is the root login for my new VPS server?

The root login is the same password our system sent you in your welcome email. You just change...

What is the path to PERL?

The path to PERL in PERL script is:#!/usr/local/bin/perl

Do you troubleshoot scripts and apps?

Hello,Sorry, but troubleshooting sripts and apps needs to be done by the scipt maker or a...

Can I change my web hosting main domain name?

Yes, and it's very easy.Just add a support ticket like this:  old: olddomain.comnew:...