GoldenGonaz
GoldenGonaz

Reputation: 1166

mod_rewrite change extensions .gif/.jpg to .png

The rule I have been fruitlessly working with doesn't work, I am trying to get all images in 1 directory to load as .png The images in the directory are a mixture of .png, .jpg and .gif

I want to be able to load the file tree.jpg by going to tree.png (no files have the same name). I am sure my mistake is obvious or my entire attempt is wrong, I just can't work it out.

The htaccess file is in the same folder with the images, which is called /thumbs

RewriteEngine On
RewriteRule ^([^.]*)\.gif$ /thumbs/$1.png [R,L,NC]

I tried this also, but it just givens a broken link to both .gif and .png versions

RewriteEngine on
RewriteRule ^(.+)\.gif$ $1.png

I tried this too, but it adds in my server path to the URL for some reason

RewriteEngine on
RewriteRule ^([^.]*)\.gif$ $1.png [R,L,NC]

Upvotes: 0

Views: 692

Answers (1)

anubhava
anubhava

Reputation: 785156

You can use this rule:

RewriteEngine on

RewriteRule ^([^.]+)\.png$ /$1.gif [L,NC,R]

Upvotes: 2

Related Questions