Uncategorized

How To Rewrite TimThumb URL Using .htaccess

Oleh takien• 1 Komentar Arsip
Thumbnail

Thumbnail (pixabay.com)

TimThumb is PHP script to generate and resize image via URL query. To resize image on the fly, you can access timthumb.php and pass some query in the URL.

For example to resize http://example.com/wp-content/uploads/2013/10/your-image-name.jpg to 150px width and 100px height, you can access http://example.com/timthumb.php?src=http://example.com/wp-content/uploads/2013/10/your-image-name.jpg&w=150&h=100. It’s quite easy isn’t it?

It’s easy and some people no problem with it. But if you want more fancy URL to your image path, you can done it using .htaccess rewrite. Note that this trick only works if your website run on Apache webserver and mod_rewrite is loaded.

Before:

http://yoursite.com/timthumb.php?src=http://example.com/wp-content/uploads/2013/10/your-image-name.jpg&w=150&h=100

After:

http://example.com/uploads/2013/10/your-image-name_150_100.jpg

The image link looks nice and shorter.

How to do that?

1. Place timthumb.php on your web root (usually under public_html)
2. Edit .htaccess and put this code

RewriteRule ^(.*)_([0-9]+)_([0-9]+)\.(jpg|jpeg|png|gif)$ timthumb.php?src=http://example.com/wp-content/uploads/$1.$4&w=$2&h=$3 [NC,L]

Replace example.com with your domain.

Tulisan ini sudah berumur: 12 tahun 10 bulan 21 hari. Informasi di dalamnya mungkin sudah tidak relevan, tapi nilai historisnya sangat berharga, terutama bagi saya sebagai penulisnya.

Komentar (1)

Arsip Statis
Jay
Not working for me. My website is http://forexminute.es/ but i still see the string queried image by timthumb…