I don’t know where I went wrong but I’m generally trying to write a .htaccess file that will redirect all files which end in .tsv to .txt instead. (I don’t know why but my extension is insisting on renaming the file back. Which is fine, since it’s required by another fetch program.)
Here’s my file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.txt -f
RewriteRule ^(.*)$ $1.tsv
Now the files reside in a directory /googlebase/ and this is the ONLY directory where I need this kind of rename to happen, so I know I don’t put this code into the .htaccess file in the / directory but for some reason, my browser is ignoring the .htaccess file in the /googlebase/ directory and insist on redirecting to a 404 page.
Can anyone help? I’ve seen code like this work when renaming .php to .html and the link so I figured it should work regardless. The file that ends in .tsv exists but I want it so that any who tries to reach a .tsv file is taken to the .txt file to download instead.
Try using this in your .htaccess file in your document root ( / ):
I may have misunderstood what you were trying to do, if the tsv/txt was the other way around, you can just change them in the conditions/rules.
Edit:
I think the main problem with what you had was that you were checked -f on the request with a .txt appended to the end. So when someone requests “/googlebase/foo.txt”, you were checked if the “/googlebase/foo.txt.txt” file exists. The code where I match (.+).tsv and then use the %1 as a backreference is just the foo part of the request (%1 = foo), so I can append a .txt to the end when I check if the file exists.