How to enable CORS for your website?

A request for the website resource like images or fonts from outside of the origin website is known as a cross-origin request. It is a security mechanism that allows restricted resources like fonts, JavaScript code etc. on a website page to be requested from a 3rd party domain outside the domain from which these resources were served. Using CORS, you can control the website resources on who can access it.

CORS on a website hosted on Linux Environment

You can add the below line in your .htaccess file where cross-domain scripting is required.

<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</ifModule>

CORS on a website hosted on Windows Environment

For Windows hosting accounts, create or modify the web.config file in the directory where you want to permit CORS requests. Add the following lines to the web.config file:

To enable CORS on the windows website, you can just add the below lines.

<configuration>
   <system.webServer>
     <httpProtocol>
       <customHeaders>
           <add name="Access-Control-Allow-Origin" value="*" />
        </customHeaders>
     </httpProtocol>
   </system.webServer>
</configuration>

Related Articles

How to check your VPS Disk Drive is SSD or HDD?

We use HyperV virtualization technology for our Denver based Classic and SSD Windows VPS. We have...

PHP Fatal error: Cannot redeclare

If your browser saw an error message PHP Fatal error: Cannot redeclare function it is an issue...

Where do i put my review for Accuwebhosting.com?

Here, is a list of website links where you can put your reviews for Accuwebhosting....

MySQL timeout errors.

If your website is running with long and heavy queries, you may receive the MySQL timeout error....

How to Remove IP Address from Gmail Blacklist?

If you are receiving bounce back emails from Gmail, your IP address might be on the Gmail...

  • 0 Users Found This Useful

Was this answer helpful?