Better URL for images with mod_rewrite
Apache is a popular server platform which among other things includes an URL rewriting function called mod_rewrite. This function is usually used to rewrite URL:s for documents in order to make them more SEO-friendly.
mod_rewrite is applicable for images
Actually its pretty obvious that mod_rewrite works for images as well. Among other things, this technique is used for protection against hotlinking (preventing images being shown on external domains). So, why not use mod_rewrite for better looking URL?
Lets say that you have a product page for Ericsson w880 at:
http://mnowak.se/mobiler/ericsson-w880/
The product picture has the URL:
http://mnowak.se/123.jpg
Wouldn’t it be better if the picture URL was:
http://mnowak.se/mobiler/ericsson-w880/ericsson-w880.jpg ?
Furthermore, this URL is better for SEO-purposes.
The above can be achieved with .htaccess containing:
RewriteEngine on
RewriteBase /
RewriteRule ^/?mobiler/ericsson\-w880/ericsson\-w880\.jpg$ 123.jpg [L]
This script is not optimal in any way and definitely not dynamic. However, it shows that it is possible.
Note: The script works but is not used for the links above simply because I did want to mess with the existing rewrite rules.