Web2.0, HPC, Unix, and my mine.
CodeIgniter Routes Trick – Removing Controller Names from the URI to Keep URLs Short.
ช่วงนี้ บริการจำพวก URL Shortener Service กำลังมาแรง เช่น bit.ly goog.gl youtu.be fb.me เป็นต้น ผมก็อยากจะลองทำเวบพวกนี้ บน Codeigniter เหมือนกัน สำหรับคนที่เคยใช้ codeigniter จะรู้ว่าระบบ URI ของ CI จะต้องมีรูปแบบดังนี้ http://localhost/controller/function/parameters นั่นหมายถึง มันยาวมากเลย แต่ผมต้องการ http://localhost/parameters เลยอ่ะคับ ไปลอง Google เลยมาโน๊ตเก็บไว้หน่อย เด๋วพอจะใช้แล้วหาไม่เจออีก
เปิดไฟล์ application/config/routes.php
เติมคำสั่งนี้ลงไป
$route['^(?!video|url).*'] = ‘controller/function/$0′;
คำอธิบาย หมายถึงให้ Route URI ที่ไม่ได้ขึ้นต้นด้วยคำว่า video หรือ url ไปที่ๆ ต้องการ
| Print article | This entry was posted by klainfo on February 3, 2010 at 6:13 pm, and is filed under Web, codeIgniter. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
