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 do i setup rDNS/PTR record at Accuwebhosting?

Client can't set rDNS record at their end. You will need to submit a support ticket with the IP...

How to renew SSL?

If you have an existing SSL Certificate purchased from Acuwebhosting, you just need to update us...

Does Mobile application requires hosting service?

Yes, you need a hosting service for the application backend to manage the following thing....

What are the Differences Between Forward Proxy and Reverse Proxy?

Generally, there are two types of proxy servers available which are Forward Proxy and Reverse...

Free Anti-Malwares/ for Windows and Linux based Servers

As we all know, the internet is open and your server may receive threats of malware and Spywares...

  • 0 Users Found This Useful

Was this answer helpful?