mod rewrite สำหรับ รับค่า $_GET จาก URL .html

[ENGLISH DEV]
many people ask some question, How to make rewrite rule in .htaccess with mod_rewrite in apache. the rule use to get query string from .html url, i try to make this with few time and i found how to solve this problem, follow this.
- Firstly make .htaccess file.
- For get querystring from url “http://www.codeans.com/country/6/rewrite.html?buffer=secret” and bind to “http://www.codeans.com/rewrite.php?country=6&buffer=secret” please fill below code to .htaccess

Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^country/(.*)/\.html([?].*)? rewrite.php?country=$1&%{QUERY_STRING} [L]

Result

make file rewrite.php and put below code for display output

print
<pre>”
;
print_r($_GET);

:) Enjoy Codeans!!!

[THAI DEV]
หลายท่านเคยถามคำถาม, ว่าวิธีการเขียน mod rewrite ในการหาค่า querystring($_GET) จาก URL ที่มีนามสกุล .html ผ่าน .htaccess กับ mod_rewrite ใน apache ต้องทำอย่างไร? ผมจึงพยามคิดสูตรการเขียน จึงได้คำตอบดังนี้ครับ
- สร้างไฟล์ .htaccess.
- เขียน Rule สำหรับการรับค่า querystring จาก url “http://www.codeans.com/country/6/rewrite.html?buffer=secret” และให้ rule อ้างถึง “http://www.codeans.com/rewrite.php?country=6&buffer=secret” ใน .htaccess

Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^country/(.*)/\.html([?].*)? rewrite.php?country=$1&amp;%{QUERY_STRING} [L]

ผลลัพท์

สร้างไฟล์ rewrite.php และเขียนโค๊ดเพื่อแสดงผลลัพท์

print
<pre>”
;
print_r($_GET);

:) สนุกกับการเขียนโค๊ดกับ Codeans ครับ!!!

About the Author