.jpg to .php with ModRewrite

ยัดโค๊ดใส่ใน .htaccess ตามข้างล่าง

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.jpg$ $1.php
</IfModule>

ใส่ .htaccess ไปใน Folder ที่อยากเปลี่ยนเวลาที่โดนเรียกชื่อไฟล์ Apache ก็จะเปลี่ยนให้เราเอง ทีนี้ก็จะเรียก Dynamic Picture โดยใช้นามสกุลของรูปภาพตรงๆ แบบ .jpg ได้

Example :

เวลาเรียกไฟล์นี้ http://btk.ac.th/gd/tweet.jpg  ตัว Sever Apache ก็จะโดน Rewrite ไปเป็น http://btk.ac.th/gd/tweet.php แทน

ใช้งานได้เหมือนไฟล์รูปปกติ

http://btk.ac.th/gd/tweet.jpg

Show Lastest TwitPic PHP Script

<?
//TwitPic Username same as twitter..
$username = "Username" ; //username Case Sensitive!!

//Size of Image "mini" 75 px ,"thumb" 150px , "full" Actual size.
$size = "full" ; // size "mini","thumb","full"

//Get content
$html = file_get_contents('http://twitpic.com/photos/'.$username);
$matches = null;
$r = preg_match_all('/a href="\/([0-9a-zA-Z])+"/', $html, $matches);
$link = $matches[0];
$filename = str_replace('"', '', str_replace('a href="/', '', $link[0]));
$image_url = 'http://twitpic.com/show/'.$size.'/'.$filename;

header("Location: $image_url"); //redirect to the image
?>

แก้ไข Username และขนาดที่ต้องการ ก่อนนะ
เวลาเอาไปใช้ก็ save แล้วก็ link ด้วย tag image ธรรมดาเหมือนสคริปเราคือรูปนั่นแล

<img src=”twitpic.php” >  เช่นนี้แล