Timthumb htaccess rewrite

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 19:14:50

问题


Since like a day, my timthumb stopped working

however did figure out that it has probably to do with the modsecurity.

So the following, which worked untill a day ago.

http://www.HOST.com/wp-content/themes/THEME/scripts/timthumb.php?src=http://www.HOST.com/wp-content/uploads/2013/05/image.jpg&w=70&h=50&zc=1&q=100

Now only works using

http://www.HOST.com/wp-content/themes/THEME/scripts/timthumb.php?src=/wp-content/uploads/2013/05/image.jpg&w=70&h=50&zc=1&q=100

Tried putting this in my htaccess, but no change

# WPhtc: Begin Custom htaccess
RewriteCond %{REQUEST_URI} !^/(timthumb) [NC]
RewriteRule ^scripts/timthumb.php?src=/(.*)x(.*)/r/(.*) scripts/timthumb.php?src=http://www.HOST.com/$3&h=$2&w=$1&c=1
# WPhtc: End Custom htaccess

回答1:


Using TimThumb for your images, can lead to some.. messy looking (and lest face it, unattainable) code. Observe..

<img alt="Camping" src="/timthumb.php?src=/images/feb/image_001.jpg&amp;w=250&amp;h=250&amp;" />

Why not take the messy out of it and use some funky .htaccess redirects?

<img alt="Camping" src="/images/feb/250/image_001.jpg" />

Doesn’t that look much better? Your wonderful camping image is now set to 250 pixels in width with the height being maintained at the correct ratio.

TimThumb htaccess rewrite It is very easy and simple to achieve this! Update your .htaccess file, Like so.

# With your other RewriteCond rules
RewriteCond %{REQUEST_URI} !^/(images) [NC]
RewriteRule ^(.+)/$ /$1 [R,L]

# Width
RewriteRule ^images/([a-zA-Z0-9-]+)/([0-9]+)/([a-z0-9.]+)?$ /tt.php?src=/images/$1/$3&amp;w=$2

If you don’t have any sort of folder system and all your images are just thrown into the images folder, you can just use the following

RewriteRule ^images/([0-9]+)/([a-z0-9.]+)?$ /tt.php?src=/images/$2&amp;w=$1

Source



来源:https://stackoverflow.com/questions/16720646/timthumb-htaccess-rewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!