I have 10 sub domains and getting all static files from a sub domain (static.88n8.com).
I want to allow cross origin for all sub domains in .htaccess with this:
SetEnvIf Origin "^http(s):\/\/(www\.google.com|google\.com|88n8\.com|second\.88n8\.com|third\.88n8\.com|fourth\.88n8\.com)$" OriginDomainStr=$0
Header add Access-Control-Allow-Origin %{OriginDomainStr}e env=OriginDomainStr
Or this one:
SetEnvIf Origin "^http(s):\/\/(www\.google.com|google\.com|88n8\.com|second\.88n8\.com|third\.88n8\.com|fourth\.88n8\.com)$" OriginDomainStr=$0
Header set Access-Control-Allow-Origin %{OriginDomainStr}e env=OriginDomainStr
Or this one:
SetEnvIf Origin "^http(s):\/\/(www\.google.com|google\.com|88n8\.com|second\.88n8\.com|third\.88n8\.com|fourth\.88n8\.com)$" OriginDomainStr=$0
Header always set Access-Control-Allow-Origin %{OriginDomainStr}e env=OriginDomainStr
And console showing me:
Access to font at 'https://static.88n8.com/font.woff' from origin 'https://88n8.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Which is very weird. That regex should match but seems it doesn't match at all.
I tried this one to check if I can set the header and it worked for main domain:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "https://88n8.com"
</IfModule>
I don't want to use *
or single domain. Why my regex never match in .htaccess? Seems my Regex test is OK.
Disclaimer: 88n8.com is an example to show my domain is including numbers and English characters in it. It's not my real domain and I don't own that.
Edit 1
As you can see in my REGEX, it should be applied to all 88n8.com
sub domains and google.com (with https
or http
).
I have only included 4 sub domains in my REGEX to show you my REGEX.
Edit 2
I've added this code to my PHP pages to know current Origin:
echo (isset($_SERVER['HTTP_ORIGIN']))? $_SERVER['HTTP_ORIGIN'] : 'NOT SET';
and the result is NOT SET
. Seems my Origin
is empty or NULL and That's the reason REGEX never match.
Edit 3
I've checked the server IP with IP2Proxy. This is the Proxy Detection Result:
Edit 4
I've tried to select anything but still no chance with these two REGEX:
SetEnvIf Origin "." OriginDomainStr=$0
Header add Access-Control-Allow-Origin %{OriginDomainStr}e env=OriginDomainStr
SetEnvIf Origin "^(?![\s\S])" OriginDomainStr=$0
Header add Access-Control-Allow-Origin %{OriginDomainStr}e env=OriginDomainStr
How can I see the value of Origin directly?