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

what is mod security? How to fix the 403 forbidden error in WordPress?

Mod Security is a web app firewall (WAF). It monitors and blocks the malicious incoming...

How to set outlook rule to receive emails to inbox?

You may face an issue where your emails are moving to the recipient spam box instead of Outlook...

How to add/host a website to VPS and point the domain to VPS?

Point 1: How to Add Website & Use Name Server of your VPS? (1) Host a website in the...

How to activate SSL Certificate?

You can activate SSL Certificate to get secure connections on your website. Looking to purchase...

How to register domain and make the payment?

If you are a registered client, you can directly refer to the following steps to order a new...

  • 0 Users Found This Useful

Was this answer helpful?