I have a small ajax running with php on a server. That directory has a .htaccess which has the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exampleDomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.exampleDomain.com/$1 [R,L]
This part is meant to redirect the http requests to https. However, I call the ajax from outside the domain, so I added:
Header set Access-Control-Allow-Origin "*"
This is meant to tell the browser to ignore CORS policy.
I am using jQuery to make a get request (I don't think jQuery is the problem), and it only works with https. If I make a request to http://exampleDomain.com, the server will not respond with the access-control-allow-origin header. On the contrary, http://www.exampleDomain.com, https://www.exampleDomain.com and https://exampleDomain.com all respond with the header. I want to keep the HTTP upgrade functionality, whether that is using .htaccess or not, without it interfering with the headers sent back.
This is the code that makes the failed request:
$.get("http://exampleDomain.com/path/to/file.php", {}, res => console.log(res))
Ideally, I would just change the request to https, but the code is already in production.
I am using Apache2 and PHP7.