 |
การเขียนเงื่อนไข Mod Rewrite ทำ list reccord ครับ รบกวนขอคำแนะนำหน่อยครับ |
|
 |
|
|
 |
 |
|
แบบนี้เลยครับ
Code (PHP)
RewriteEngine On
RewriteRule ^category/$ list.php [L]
#http://localhost/project/category/ >> หน้ารวมเนื้อหน้าเนื้อหา (list)
RewriteRule ^(.*)/(.*).html viewdetail.php?id=$1&keyword=$2
#http://localhost/project/category/0001.html >> หน้าแสดงเนื้อหา (detail)
|
 |
 |
 |
 |
Date :
2012-08-07 14:09:21 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ K.คนธรรมดา ไม่พิเศษ มากครับ
ผมสอบถามเพิ่มหน่อยครับ [L] หมายถึงอ่ะครับ
และในหน้า list.php ของผมมันต้องรับค่า keyword=$2 มาเพื่อน query ด้วยอ่ะครับ ผมลองเอาตัวอย่างที่คุณ K.คนธรรมดา ไม่พิเศษ แล้วมัน error อ่ะครับ
|
 |
 |
 |
 |
Date :
2012-08-07 14:32:29 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ้างจาก ในหน้า list.php ของผมมันต้องรับค่า keyword=$2 มาเพื่อน query ด้วยอ่ะครับ
ในหน้า list.php ต้องส่งและรับค่าอะไรบ้างอ่ะครับ คือ ปัญหาของคุณนี่น่าจะมาจากการกำหนด (.*) น่ะครับ ถ้าหากเจาะจงได้ก็กำหนดแบบตายตัวดีกว่า เช่น
RewriteRule ^home/$ index.php
|
ประวัติการแก้ไข 2012-08-07 14:40:19
 |
 |
 |
 |
Date :
2012-08-07 14:39:53 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในหน้า list.php ผมเวลาผมทำลิงค์จากเมนูจะได้อย่างนี้ครับ
Code (PHP)
list.php?cat=mm
เมื่อหน้า list.php รับค่า $_GET['cat'] มาแล้วจะทำการ query ออกมาเป็น id ต่างๆ ถ้าจะไปดูรายละเอียดก็คลิกหัวข้อโดยผมทำลิงค์เป็นอย่างนี้ครับ
Code (PHP)
viewdetail.php?cat=<?=$rs['CatID']?>&id=<?=$rs['ConID']?>
รูปแบบของ url ที่ผมอยากได้คือเมื่อคลิกดูหมวดหมู่
localhost/mm/
รูปแบบของหน้าแสดงรายละเอียดของบทความในหมวดหมู่นั้น
localhost/mm/0001.html (0001 เป็น ConID ของบทความครับ)
รบกวนขอคำแนะนำหน่อยครับ
|
ประวัติการแก้ไข 2012-08-07 14:54:21
 |
 |
 |
 |
Date :
2012-08-07 14:52:33 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นทำแบบนี้ก็ได้ครับ
Code (PHP)
rewriterule ^(mm|yy|uu)/$ list.php?cat=$1
และในส่วนนี้ก็
viewdetail.php?cat=<?=$rs['CatID']?>&id=<?=$rs['ConID']?>
Code (PHP)
rewriterule ^(mm|yy|uu)/(.*)\.html$ viewdetail.php?cat=$1&id=$2
หมายเหตุ : ในส่วนของ (mm|yy|uu) คือค่าที่ต้องการรับครับ ถ้ามีหลายค่าก็ใช้หมาย | คั้น ความหมายของมันคือ mm หรือ yy หรือ uu ให้แสดงหน้า list.php?cat=$1 ครับ
|
ประวัติการแก้ไข 2012-08-07 15:01:16 2012-08-07 15:02:21
 |
 |
 |
 |
Date :
2012-08-07 14:58:35 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนอีกนิดนะครับ
ค่า mm ของผมมันได้มาจากการ query ใน categoryอ่ะครับ
จริงก็คือ
Code (PHP)
list.php?cat=<?=$objResult['CatName']?>
เพราะฉะนั้นในวงเล็บ (mm|yy|uu) ผมควรเขียนยังไงดีครับ หรือให้เงื่อนไขนี้เขียนยังไงดีครับ
รบกวนหน่อยนะครับ ^^
|
 |
 |
 |
 |
Date :
2012-08-07 15:09:51 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
"ค่า mm ของผมมันได้มาจากการ query ใน categoryอ่ะครับ" อันนี้เริ่มลำบากนิดหน่อย 555+
ถ้าแก้แบบธรรมดาๆเลยคือ ในฐานข้อมูลมีอะไรบ้าง ก็เพิ่มในไฟล์ .htaccess ให้เหมือนกัน แต่มีข้อเสียคือถ้าในอนาคตมีสินค้ามากๆ เราก็ต้องมานั่งเพิ่มใน .htaccess (ผมคิดว่ามันน่ารำคาญนิดๆ )
หรือไม่ก็อาจจะมีอีกวิธีนึงคือ ค่า mm หรือตัวอื่นๆเนี่ยมีกี่ตัวอักษร ถ้ามี 2 ตัวอักษรเท่ากันหมดก็ง่ายหน่อยครับเราอาจเขียนได้โดยกำหนดว่าค่าที่รับมาถ้าหากมี 2 ตัวอักษร ก็ให้ทำงานในหน้า list.php (แต่โค้ดต้องหาก่อนครับ เพราะไม่ค่อยได้ใช้ จเอแล้วจะเอามาแปะให้ สักครู่ๆ)
|
 |
 |
 |
 |
Date :
2012-08-07 15:23:02 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ K.คนธรรมดา ไม่พิเศษ
มีแค่ 2ตัวอักษรครับ... ^^
|
 |
 |
 |
 |
Date :
2012-08-07 15:28:40 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ส่วนเรื่อง [L] อ่านรายละเอียดตามนี้เลยครับ
RewriteRule
Regular expressions
Some hints about the syntax of regular expressions:
Text:
. Any single character
[chars] One of chars
[^chars] None of chars
text1|text2 text1 or text2
Quantifiers:
? 0 or 1 of the preceding text
* 0 or N of the preceding text (N > 0)
+ 1 or N of the preceding text (N > 1)
Grouping:
(text) Grouping of text
Anchors:
^ Start of line anchor
$ End of line anchor
Escaping:
\ char escape that particular char
Pattern Matching metacharacter Definitions
\ Use before any of the following characters to escape or null the meaning or it. \* \. \$ \+ \[ \]
^ Start matching at this point
$ End point of the match
. Any character
[] Starts a range
| Starts alternative match this|that would mean match this or that
() starts a back reference point
? match 0 or 1 time Quantifier
+ match atleast 1 or more times Quantifier
* match 0 to infinite times Quantifier
{} match minimum to maximum Quantifier {0,3} match up to 3 times
Range Definitions []
^ Negates the class. [^A-Z]+ means don’t match any uppercases
\ Use before any of the following characters to escape or null the meaning or it. [\+]+
- Range for matching [0-9]+ [a-zA-Z]+
Command Flag
[R] Redirect you can add an =301 or =302 to change the type.
[F] Forces the url to be forbidden. 403 header
[G] Forces the url to be gone 401 header
[L] Last rule. (You should use this on all your rules that don’t link together)
[N] Next round. Rerun the rules again from the start
[C] Chains a rewrite rule together with the next rule.
[T] use T=MIME-type to force the file to be a mime type
[NS] Use if no sub request is requested
[NC] Makes the rule case INsensitive
[QSA] Query String Append use to add to an existing query string
[NE] Turns of normal escapes that are default in the rewriterule
[PT] Pass through to the handler (together with mod alias)
Skip the next rule S=3 skips the next 3 rules
[E] E=var sets an enviromental variable that can be called by other rules
|
 |
 |
 |
 |
Date :
2012-08-07 15:36:18 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
Rewriterule ^([a-z][a-z])/$ list.php?cat=$1
รูปแบบ url ได้อย่างที่ต้องการแล้วครับ http://locahost/project/mm
แต่มันไม่ไม่แสดงผล
ผมเลยทำอย่างงี้แทนครับ
RewriteRule ^list-(.*).html list.php?cat=$1
แสดงรายการเรียบร้อยแล้วครับ เอาเป็นว่าใช้อย่างนี้ไปก่อน พอมีเวลาเหลือเดี๋ยวจะย้อนกลับมาใหม่ ^^ (แอบคาใจอ่ะครับ)
อย่างไรก็ตามต้องขอขอบคุณมากนะครับ คุณคนธรรมดา ไม่พิเศษ
|
 |
 |
 |
 |
Date :
2012-08-07 16:30:21 |
By :
pokultra |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|