Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to simply a list of about 99 domains to enable CORS on?

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
like image 589
MShack Avatar asked Oct 15 '25 19:10

MShack


1 Answers

This seems to work , anyone review and see if ok

<IfModule mod_headers.c>
    SetEnvIf Origin "http(s)?://(www[1-9][0-9]?\.example\.com)$" AccessControlAllowOrigin=$0
        Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
        Header merge Vary Origin
</IfModule>
like image 198
MShack Avatar answered Oct 18 '25 14:10

MShack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!