Hi,
Let's say I have x.com and y.com. On z.com, I have a directory called x.com/ and another called y.com/. I have a CNAME record mapping x.com and y.com to z.com.
What I want to achieve is this;
A file is accessed on one of the end domains;
x.com/test.txt
This should then map to;
z.com/x.com/test.txt
The way I thought of going about this is:
RewriteCond %{REQUEST_URI} !^https:\/\/z\.com\/switch.php\?.+ [NC]
RewriteRule ^(.*) https:
I would then use switch.php to echo $_SERVER['HTTP_HOST']/file.txt where the filepath is specified in $_GET['f'], placed there by .htaccess.
Not only does the .htaccess cause an infinite loop, but I believe it's possible to do this just in .htaccess without switch.php at all. The loop is because the regex isn't working to exclude the file being rewritten to. I'd imagine this is because the $1 has no capture group in the regex, but I have no idea how to create a capture group while having a negated regex. I'd need to say 'if it's not switch.php?anything, set $1 to whatever's after the hostname'.
Adding this rule stops the infinite loop but no rewriting happens:
RewriteCond %{REQUEST_URI} ^https:\/\/z\.com\/(.+) [NC]
If you could help me to fix this I'd really appreciate it.
What I have tried:
Everything mentioned in question, plus a lot of googling