1

I have a collection of images in specific folders by category on my website. Each image has an ID which is also it's name. The images can be either PNGs or JPGs.

If a PNG image had an ID of abc123 how could the URL be example.com/category/abc123/ and have the server point to /images/category/abc123.png and not /images/folder/abc123.jpg and vise versa?

I want to try something with .htaccess RewriteCond & RewriteRule but i'm not positive how I would do it.

0

2 Answers 2

1

A very simple and painless solution is to use Options +MultiViews. What it does is simple: if the server gets a requests for a file it can't find, it searches for any files in the same direction with the same name + any file extension (e.g., foo would match foo.jpg or foo.png, but not foobar.jpg) and reads that file instead. If more than one match is found, then server "chooses the best match to the client's requirements, and returns that document".

Read more here

1
  • I like this idea, I'll take a look at it and get back with you, thanks. Nov 24, 2012 at 5:43
0
RewriteEngine On
^category/.*/ /images/category/$1.png

Try it.

1
  • How would this account for any jpg images? Nov 24, 2012 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.