We are trying to implement CDN77 in wordpress with genesis framework and want to serve different robots.txt for CDN. We used the following code
RewriteEngine On
RewriteCond %{HTTP:VIA} !^.*\.rsc.cdn77.org$
RewriteRule ^robots\.txt$ robots_cdn77.txt [L]
Our website is https://example.com and we have added a CND CNAME for https://cdn.example.com
We are facing the issue that our main robots.txt is getting rewritten alongwith the robots.txt for CDN website. Both robots.txt become same for above links. Both https://example.com/robots.txt and https://cdn.example.com/robots.txt serve the same resource.
How would I change the rewriterule such that each link serves their own robots.txt instead?
I would suggest you to setup a rule in CDN configuration. Saying for example when https://example.com/robots.txt is requested before it contacts origin server it append something like /cdn/robots.txt once the response in received from origin server, serve it as /robots.txt it self. This is possible in akamai CDN. Not sure which one are you using.