Menu
Mod Rewrite ใน Localhost

Mod Rewrite ใน Localhost

 คนทำเว็บ  2015-11-12 11:49:10  4,173

PHP : Mod Rewrite ใน Localhost

หลายครั้งที่ต้องมีการทดสอบ Mod Rewrite บนเครื่อง Localhost แต่เนื่องจาก Path ไม่ตรงกับบน Server ที่ใช้งานจริง วันนี้เรามาเรียนรู้การกำหนด File .httaccess เพื่อให้สามารถใช้งาน บน Localhost ของเราได้ครับ

1. ทดสอบว่า locahost ของเราสามารถรัน mod rewrite ได้แล้ว

2. สร้าง .htaccess โดยใส่ข้อมูลด้านล่างนี้


AddDefaultCharset utf-8

Options +FollowSymLinks
Options +Indexes
Options -Multiviews

#SAMPLE
#RewriteRule ^content/([^/]*)\.htm$ /my_php/my_website_folder/content_view.php?id=$1 [L] 

RewriteRule ^content/([^/]*)\.htm$ /PATH_FOLDER_WEBSITE/content_view.php?id=$1 [L]

RewriteEngine On

3. ทดสอบ URL ต้องสามารถรันได้ 
จากตัวอย่างด้านบน http://localhost/content/id.htm


มาเป็นเพื่อนกันครับ บนช่องทาง Social ด้านล่างนี้ครับ

--------------------------
► LINE@ : @siamfocus.com
► Facebook : fanpage.siamfocus
► Twitter (X) : siamfocus
► Linkedin : taam-siamfocus
► Instagram : iamtaam
► Youtube : SiAMFOCUS
► Tiktok : @taamsiamfocus
--------------------------

รับทำเว็บไซต์ สอนทำเว็บไซต์ รับดูแลเว็บไซต์

สายด่วนโทร 061-583-7888

บทความแนะนำ