How to enable cors in apache2 and xampp?


by tina , in category: General Help , 2 months ago

How to enable cors in apache2 and xampp?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by caesar_kertzmann , 2 months ago


To enable CORS in Apache2 and XAMPP, you can add the following code to your Apache configuration file:

  1. Open your Apache configuration file. This file is typically located at /etc/apache2/apache2.conf on Linux systems or in the conf folder of your XAMPP installation.
  2. Find the tag that corresponds to the directory you want to enable CORS for. This is typically the directory where your website files are located.
  3. Add the following lines inside the tag:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"

  1. Save the changes to the configuration file and restart Apache to apply the changes. On Linux systems, you can do this by running the following command:
sudo systemctl restart apache2

Once you have enabled CORS in Apache2 or XAMPP, requests from other domains should now be able to access your resources.