0
votes

I need to rewrite my images urls for better SEO using Timthumb.

I have this htaccess file (on Codeigniter) that It works, but when i past an url rewritten (es. http://www.example.com/products/loremipsum-450x600.jpg) It redirect to: http://www.example.com/resize/timthumb.php?src=http://www.moveshop.com/uploads/loremipsum.jpg&w=450&h=600

Is it possible to rewrite without redirect? Thanks

-- My htaccess file is:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /    
RewriteRule ^(products)/(.*)-([0-9]{1,4})x([0-9]{1,4}).(jpg) http://www.example.com/resize/timthumb.php?src=http://www.example.com/uploads/$2.$5&w=$3&h=$4 [R=301,L]

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>
1
Simply remove R=301, at the end of the rule. - Hashem Qolami
@HashemQolami the http:// part of the rule's target implicitly redirects - Jon Lin
@JonLin Ah right.. missed that. - Hashem Qolami

1 Answers

2
votes

If the htaccess file is on the same server as the destination (e.g. www.example.com, then you need to remove the host/scheme from your rule and the R flag:

RewriteRule ^(products)/(.*)-([0-9]{1,4})x([0-9]{1,4}).(jpg) /resize/timthumb.php?src=http://www.example.com/uploads/$2.$5&w=$3&h=$4 [L]

If they are not on the same server, then you need to reverse proxy, which means you must have mod_proxy loaded. You'll just need to replace the R flag with the P flag:

RewriteRule ^(products)/(.*)-([0-9]{1,4})x([0-9]{1,4}).(jpg) http://www.example.com/resize/timthumb.php?src=http://www.example.com/uploads/$2.$5&w=$3&h=$4 [P,L]