I have the following problem, if I upload any file to my web server it automatically renames the file to an uppercase extension. For instance:
If I upload picture.jpg my server automatically changes it to picture.JPG
If I use <img src="picture.jpg"> my server returns a 404 error but if I use <img src="picture.JPG"> then the server displays the image.
Can the .htaccess solve this issue? something with RewriteRule and RewriteCond?
RewriteCond %{HTTP_HOST} ^$\.jpg [NC]
RewriteRule ^(.*)$ $1\.JPG [R=301,L]
Any help will be greatly appreciated!
Thanks!
Try adding this to the htaccess file in your document root:
You were pretty much on the right track, except that you don’t want to match against the
%{HTTP_HOST}variable (since it’s only a hostname). I’ve added some more conditions to check first that if the JPG extension was capitalized, that there would actually be a file there before it rewrites to all caps JPG. The%1is a backreference to the match in the first rewrite condition^/(.+)\.jpg$.