Many of you love using timthumb in your wordpress theme but don’t use it because it does not generates seo friendly urls for images. I was asked by a client to make timthumb urls seo friendly and here is how I did that.
First open your wordpress site .htaccess file. Generally it is located in root of your wordpress installation.
It should look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Now create new folder in your root call it let’s say images and place cache folder and timthumb in there then edit your .htaccess file as below
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(images) [NC]
RewriteRule . /index.php [L]
RewriteRule ^images/(.*)x(.*)/r/(.*) images/timthumb.php?src=http://example.com/$3&w=$1&h=$2&zc=1&q=100&a=tl
</IfModule>
# END WordPress
Replace example.com with you site name:
Now upload htaccess file and where you need to use timthumb do as below
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<a href="'.get_permalink().'"><img src="'.get_bloginfo('url').'/images/715x440/r/'.str_replace(array('http://example.com/', 'http://www.example.com/'), array('',''), $thumbnail[0]).'" width="715" height="440" alt="'.get_the_title().'" /></a>';
endif;
?>
That should do the trick for making timthumb url seo friendly.