How to enable cors in apache2 and xampp?

Member

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

How to enable cors in apache2 and xampp?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by caesar_kertzmann , 8 months ago

@tina 

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:
1
2
3
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:
1
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.