I currently have .htaccess
file that lists dozens of domains to enable CORS to from my server.
I shortened my example below , but all the domain names are similar and the only part of the domain name that is changed is the 1 or 2 digit number after the www.
<IfModule mod_headers.c>
SetEnvIf Origin "http(s)?://(www48.example.com||www47.example.com)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header merge Vary Origin
</IfModule>
so in this example i have CORS enabled for
https://www48.example.com
https://www47.example.com
I was wanting a simpler way to enable a list of of 99 domains with similar names. So all domain names are identical aside of digits 1 to 99 after the "www" , how can I achieve this without listing all 99 domain names individually?
https://www1.example.com
https://www2.example.com
....
https://www10.example.com
....
https://www40.example.com
....
https://www70.example.com
....
https://www99.example.com
2
Answers
This seems to work , anyone review and see if ok
You can achieve this by using a regular expression in the SetEnvIf Origin line. Your .htaccess file would look like this:
In the regular expression www[1-9][0-9]?.example.com, the [1-9][0-9]? part matches one or two digits from 1 to 9. Here is how it works: