views:

30

answers:

1

I'm designing an image repository. I want to uncouple the filename from the image html link. For instance:

  • image in filesystem is called images/items/12543.jpg
  • HTML is <img src="images/car.jpg" />

Does anyone strongly discourages me to rewrite all image requests using PHP so when retrieving images/car.jpg, Apache really replies content from images/items/12543.jpg?

I don't know if I may get performance problems.

+4  A: 

It may take a long time until you will get actual performance problems with this, but running each request for a resource through PHP (every process, especially when connecting to a database or doing other complex things, taking up considerable memory on each request) is a bad idea architecturally IMO.

I would recommend either translating 12543 to car in the file system already, and then doing a (cheaper) URL rewrite for it:

* images/items/car.jpg
* <img src="images/car.jpg" />

Alternative idea: How about doing it like Stack Overflow. Name the jpeg 12543.jpg and do

<img src="images/12543/car.jpg"> 

(The car part being arbitrary and there only for the user's and search engines' enjoyment - what is really parsed by the rewrite rule, and used to fetch the image, is only the 12543 and the .jpg).

Pekka