Prerequisites

You must have enabled Apache headers modules. For the Ubuntu and other Debian based systems execute the following command to enable headers modules.

Enable CORS in Apache

Set Access-Control-Allow-Origin (CORS) authorization to the header in Apache web server. Add the following line inside either the , , sections under in Apache configuration files. You can also place this inside the .htaccess file.

Example

To allow Access-Control-Allow-Origin (CORS) authorization for all origin domains for all files inside a directory.

To allow Access-Control-Allow-Origin (CORS) authorization for specific files only. For example to allow CORS for fonts only use following example:

To allow Access-Control-Allow-Origin (CORS) with multiple origin domains, Use following example

After making changes in configuration files, You need to restart the Apache webserver. But no need to restart if adding in the .htaccess file.

Restart Apache Web Server

Conclusion