|
Apache2 mod_rewrite rule for changing file extentions
I want to make a mod_rewrite rule that performs the following, but I'm failing to get the logic in order:
1) Does [filename] end in .XYZ?
2) Does [filename].ABC exist?
3) If yes, redirect [filename].XYZ to [filename].ABC. If no, do nothing.
I could just do a blunt redirect with:
RewriteRule ^(.+)\.XYZ$ $1.ABC [R=301,L]
...which works, but I don't like the idea of doing a redirect to another non-existent file, so I'd like to check if it actually exists first.
I know I can accomplish 1) with:
RewriteCond %{REQUEST_FILENAME} ^(.+)\.XYZ$
and I know I can check for files existing with:
RewriteCond %{REQUEST_FILENAME} -f
The problem is, since the filename is dynamic, and we're not checking for the actual requested file, I don't know how to do a RewriteCond -f against the potential new filename.
|