|
|
|
[ ความเห็นที่ 1]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันจันทร์ 7 พฤษภาคม 2555 20:02 น. แต่ เวลา ทำลิ้ง url ให้ใส่ rawurlencode ไปด้วย เช่น $a=rawurlencode("เว็บสนุก")."html"; เวลาใส่ลิ้งก็ เว็บสนุก
อะไรแบบนี้อะ |
|
[ ความเห็นที่ 2]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันจันทร์ 7 พฤษภาคม 2555 22:10 น.
ส่ง 2 ค่า
RewriteRule ^([^/]*)-([^/]*)\.html$ /product.php?catID=$1&catName=$2 [L] |
|
[ ความเห็นที่ 3]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันอังคาร 8 พฤษภาคม 2555 13:00 น.
อันนี้มีวีดีโอสอนด้วยครับ ไปดูเองครับ
http://www.hosttook.com/support-joomla/website-tips-and-technique/110-how-to-create-thai-url-with-modrewrite-htaccess.html |
|
[ ความเห็นที่ 4]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันอังคาร 8 พฤษภาคม 2555 13:26 น. |
|
[ ความเห็นที่ 5]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันอังคาร 8 พฤษภาคม 2555 19:22 น.
ถ้าต้องการตัดคำที่ต้องการ
$vowels = array(" ","#","!","%", "@","?","'","\""); // replace # และช่องว่างใน seo url $seo_url = str_replace($vowels,"_", $row['topic']); แล้วก็link เป็น <a href=$seourl-เลขid.htmlของคุณก็ว่าไป></a> |
|
[ ความเห็นที่ 6]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันพุธ 9 พฤษภาคม 2555 00:43 น.
ตัวอย่าง
จากเดิม http://www.yoursite.com/shop/view.php?id=555&name=nokia3210 ต้องการเปลี่ยนเป็น http://www.yoursite.com/555/nokia3210.html ต้องเขียนดังนี้
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /shop/view.php?id=$1&name=$2 [L] |
|
[ ความเห็นที่ 7]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันพุธ 9 พฤษภาคม 2555 00:52 น.
RewriteBase /abc/
อันนี้คือระบุโฟลเดอร์ |
|
[ ความเห็นที่ 8]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันพุธ 9 พฤษภาคม 2555 00:56 น.
บทความ
Mod_Rewrite คืออะไร? ตัวอย่าง URL ที่ยาว และซับซ้อน
โค๊ด:
โค๊ด:
เริ่มทำ Mod_Rewrite
.htaccess ไฟล์สำคัญในการทำ Mod_Rewrite RewriteEngine on
ต่อไปจะเป็นการนำเอา Mod_Rewrite ไปให้งาน ซึ่งผมจะเริ่มด้วยตัวอย่างง่ายๆ และเขียน Rewrite Rule ง่ายก่อน แล้วก็ยกตัวอย่างต่อไปเรื่อยๆนะครับ
ใช้ Mod_Rewrite ในการทำ Redirects
RewriteEngine on RewriteRule ^old\.html$ new.html
อาจจะดูงงๆ อธิบายเพิ่มเติมดังนี้ RewriteRule จะประกอบด้วยกัน 3 ส่วน
ขออธิบายในส่วนที่ 2 (Pattern) เพิ่มเติมดังนี้ ในส่วนนี้ประกอบด้วยเครื่องหมายสำคัญ 3 อย่างคือ เมื่อเราเขียนตามนี้ เมื่อผู้เยี่ยมชมเว็บกรอกมาเป็น old.html server ก็จะทำ transparently redirect ไปที่ new.html โดยที่ผู้เยี่ยมชมเว็บไม่รู้ตัวว่าเป็นข้อมูลอันใหม่แล้ว เพราะ URL บน browser เป็น old.html อยู่เหมือนเดิม แต่ถ้าเราต้องการให้ URL ที่ปรากฏบน browser เป็น new.html ด้วย เราก็เพียงแต่เติม [R] เข้าไปต่อท้ายบรรทัด ดังนี้
RewriteRule ^old\.html$ new.html [R]
ตัวอย่างแรก
RewriteRule ^products/([0-9][0-9])/$ productinfo.php?prodID=$1
productinfo.php?prodID=11 หรือ productinfo.php?prodID=99
products/11/ หรือ products/99/
และใน Pattern ก็จะมีส่วนที่อยู่ในวงเล็บ ( ) เป็นการเก็บค่าที่เราตรวจสอบพบ และตรงตามเงื่อนไข ซึ่งเราสามารถเอาค่านี้ ส่งไปให้ PHP ในส่วนของ Query String ได้ เราเรียกค่าที่ได้จากวงเล็บนี่ว่า back-reference ดังนั้นผู้เยี่ยมชมเว็บ(หรือ bot ก็ได้)ก็จะเห็น url เป็น products/11/ หรือ products/99/ ซึ่ง สั้นและกระชับ โดยหารู้ไม่ว่า เราได้ซ่อน URL ที่ไม่ค่อยสวยงามและอ่านยากไว้เบื้องหลัง
RewriteRule ^products/([0-9][0-9])$ products/$1/ [R] RewriteRule ^products/([0-9][0-9])/$ productinfo.php?prodID=$1
RewriteRule ^products/([0-9]+)$ products/$1/ [R]
ข้อมูลเพิ่มเติมของ Rewrite Rule
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
|
|
[ ความเห็นที่ 9]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันพุธ 9 พฤษภาคม 2555 01:16 น.
ปัญหาเมื่อเรา rewrite ใหม่แล้ว พวกรูปทั้งหลายที่เราใส่ไว้ว่า "img/pic01.jpg" มันไม่ออก
แก้ได้ด้วยการเรียกแบบ full url ครับ |
|
[ ความเห็นที่ 10]
RE : การทำ url ภาษาไทย ด้วย mod rewrite โพสต์เมื่อ: วันพุธ 9 พฤษภาคม 2555 01:27 น.
เขียน Mod rewrite แล้วมีปัญหาCSS เพี้ยน รูปไม่แสดง
วิธีแก้ ให้ใส่ ตำแหน่ง css เป็น url เต็มๆ เช่น <link href='http://www.mysite.com/style/css.css' rel='stylesheet' type='text/css' /> |
|




