The goal is to redirect a query string, such as:
mydomain.com/sheet.csv?z=abcdef
to its respective folder, appending the query string into the folder name where the respective file is located, like so:
mydomain.com/charts/abcdef/sheet.csv
I tried the following but everything I tried results in a 404 error.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^sheet.csv?z=([_0-9a-z-]+) /$1/sheet.csv [R]
DIDN'T WORK, RESULTS IN 404 ERROR.
RewriteCond %{QUERY_STRING} ^z=([_0-9a-z-]+)$ [NC]
RewriteRule sheet.csv chart/$1/sheet.csv [NC,L,R=301]
DIDN'T WORK, RESULTS IN 404 ERROR.
How can I fix this?
UPDATE
The error seems to be occurring because it is NOT redirecting but instead looking for the file:
mydomain.com/sheet.csv which does not and never will exist.
So why is it not redirecting, and how do I fix it?
UPDATE 2
I did a bunch of trial and error experiementing. I was able to make it do SOMETHING, just need to finish getting it working.
If I do this:
RewriteCond %{QUERY_STRING} ^z=([\w-]+) [NC]
RewriteRule ^ charts/%1/sheet.csv? [NC,L,R=301]
then it redirects to the url mydomain.com/home/mydomai/public_html/mydomain/charts/abcdef/sheet.csv
I tried every possible combination I could think of but still can't get it to just go to the URL
mydomain.com/charts/abcdef/sheet.csv
Please help thanks!