PART 2::::เขียน .htaccess แบบ ไฟล์เดียวครอบจักรวาล by Tee++;

เริ่มโดย Tee++;, 07 ธันวาคม 2007, 23:48:19

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

uncorp

อ้างถึงจาก: ball6847 ใน 14 กรกฎาคม 2009, 18:49:30
โห โค้ดนี้พี่ตี๋เค้าคงไม่ใช้แล้วมั้งคับ กี่ปีแล้วเนี่ย คงไปเปลี่ยนไปใช้ CodeIgniter แทนแล้ว

ลองใช้โค้ดนี้ดูแทนละกันคับ

โค้ด (.htaccess) เลือก

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


โค้ด (index.php) เลือก
<?php

$segment 
= isset($_SERVER['PATH_INFO']) ? explode('/',preg_replace('~^/?(.*?)/?$~','$1',$_SERVER['PATH_INFO'])) : array() ;


print_r($segment);
print_r($_GET);




ลองเข้าด้วย

domain.com/class/method/param1/param2?author=Tee
domain.com/class/method/param1/param2/?author=Tee
domain.com/class/method/param1/param2///////////?author=Tee

มันน่าจะออกมาเป็นแบบนี้


Array
(
   [0] => class
   [1] => method
   [2] => param1
   [3] => param2
)
Array
(
   [author] => Tee
)



แบบนี้จะสามารถใช้งานในกรณีที่เราเขียนโปรแกรมไว้ใน Subfolder ได้ด้วย ไฟล์ต่างๆที่มีอยู่จริงบนก็จะไม่ถูก rewrite ไปด้วย สามารถมองเห็นได้ปกติ แต่ถ้าไม่ปกติแสดงว่าเป็นที่โฮสท์ ซวยไป ต้องเขียน RewriteCond ดักเพิ่มเป็น case ไป

ปล. ถ้า Query String ไม่สามารถใช้งานได้ ที่ .htaccess ลองเปลี่ยน [L] เป็น [L,QSA]

คาราวะอาจารย์ตี๋หนึ่งจอก +1


โอ้ววววววววว  เข้าไปอ่านเรื่อง CodeIgniter  มึนกลับบ้านไม่ถูกเลยคับบบบบบบบบ

Manson

อยากให้ยกตัวอย่างการเขียน Rewrite Webbaord SMF จากเดิมที่เห็นกัน จะเป็น

หน้าหลัก

อ้างถึงhttp://www.domain.com/index.php

หน้าย่อยกระทู้
อ้างถึงhttp://www.domain.com/index.php/topic,645.msg5857/topicseen.html#new

เราจะเขียนอย่างไรให้ออกมาเป็น
อ้างถึงhttp://www.domain.com/ชื่่อกระทู้.html

รบกวนแนะนำหน่อยนะครับ
ขอบคุณครับ  :-* :-* :-*
[direct=http://www.newmyshop.com]ขายซิลิโคนเสริมหน้าอกl[direct=http://www.9manson.com/board]สคริปปั่นฟรีl[direct=http://www.jetana.com]โปรโมทเว็บl[direct=http://www.imusicbox.us/]เพลงใหม่

ball6847

อ้างถึงจาก: uncorp ใน 15 กรกฎาคม 2009, 17:53:41


โอ้ววววววววว  เข้าไปอ่านเรื่อง CodeIgniter  มึนกลับบ้านไม่ถูกเลยคับบบบบบบบบ

วันแรกที่ผมรู้จัก CodeIgniter ผมก็คิดแบบนี้แหละ 555+
ทิ้งช่วงไปอีกนานเลยคับ กว่าจะเข้าใจถึงขั้นพอใช้งานเบื้องต้นได้ จะว่าไปตอนนี้ยังใช้ความสามารถของ CodeIgniter ได้ยังไม่ถึง 50% เลย 555+

http://codeigniter.com/user_guide/
http://codeigniter.in.th/user_guide/
http://www.jquerytips.com/category/codeigniter/ << ลองไล่อ่านของพี่ตี๋ดูจะเข้าใจเยอะขึ้นมากเลยคับ
We use Ubuntu.

[direct=http://ng-seo.sourcelab.xyz/]AngularJS SEO Experimental[/direct]

morizaki

 :-*ขอบคุณครับ เขียน php มานาน แต่ไม่เคยทำพวก seo เลย
Mod rewrite ก็เพิ่งรู้จัก ช่วยได้เยอะเลยครับ
งมอยู่พักนึง  :-X:P :'(


nineob

 :wanwan031: ภาคแรกยังพอไหวภาคนี้ มึนตึบเลย ของคุณน่ะ

xvlnw.com

ขอบคุณมากคับ ถึงจะยัง งง หน่อย ฮ่า ๆ ๆ
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw


xvlnw.com

อ้างถึงจาก: ball6847 ใน 14 กรกฎาคม 2009, 18:49:30
โห โค้ดนี้พี่ตี๋เค้าคงไม่ใช้แล้วมั้งคับ กี่ปีแล้วเนี่ย คงไปเปลี่ยนไปใช้ CodeIgniter แทนแล้ว

ลองใช้โค้ดนี้ดูแทนละกันคับ

โค้ด (.htaccess) เลือก

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


โค้ด (index.php) เลือก
<?php

$segment 
= isset($_SERVER['PATH_INFO']) ? explode('/',preg_replace('~^/?(.*?)/?$~','$1',$_SERVER['PATH_INFO'])) : array() ;


print_r($segment);
print_r($_GET);




ลองเข้าด้วย

domain.com/class/method/param1/param2?author=Tee
domain.com/class/method/param1/param2/?author=Tee
domain.com/class/method/param1/param2///////////?author=Tee

มันน่าจะออกมาเป็นแบบนี้


Array
(
    [0] => class
    [1] => method
    [2] => param1
    [3] => param2
)
Array
(
    [author] => Tee
)



แบบนี้จะสามารถใช้งานในกรณีที่เราเขียนโปรแกรมไว้ใน Subfolder ได้ด้วย ไฟล์ต่างๆที่มีอยู่จริงบนก็จะไม่ถูก rewrite ไปด้วย สามารถมองเห็นได้ปกติ แต่ถ้าไม่ปกติแสดงว่าเป็นที่โฮสท์ ซวยไป ต้องเขียน RewriteCond ดักเพิ่มเป็น case ไป

ปล. ถ้า Query String ไม่สามารถใช้งานได้ ที่ .htaccess ลองเปลี่ยน [L] เป็น [L,QSA]

คาราวะอาจารย์ตี๋หนึ่งจอก +1

ขอวิธีการนำไปใช้งานหน่อยนะครับ พอดีจะำทำแบบเป็นภาษาำไทย สมมติว่าผมจะทำให้เป็น domain.com/ชื่อสมาชิก/ข้อมูลสมาชิก

แล้วผมต้อง Get ค่าเอาไปใช้ยังไงครับ โดยสมมติว่าชื่อสมาชิกมีช่องว่างแบบนี้ครับ   test system

1. ทำให้ test system  เป็น test-system อย่างไรครรับ
2. หลังจากทำแล้ว จะได้ว่า domain.com/test-system/ข้อมูลสมาชิก เวลาเรา Get ค่า Array[0] จะได้ test-system มา แล้วเอาไป Query ในฐานข้อมูล แต่ใรฐานข้อมูลมันเป็น test system แล้วเราจะทำไงกับมันครับ  คำตอบอาจจะเป็นประมาณว่าแปลงกลับไปเป็นช่องว่าง แล้วถามต่อครับว่าื ในกรณีที่เป็น test? system test เวลาแปลงให้ใส่เครื่องหมายต่าง ๆ เป็น - ให้หมด จะได้ test--system-test แล้วเราจะแปลงกลับถูกได้ไงครับ ก่อนที่จะเอาไปเชคกับฐานข้อมูล
3. ขอบคุณมากครับผม
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

xvlnw.com

[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

EixQzUnG

 :wanwan014:

เพื่ม db อีก 1 แถว ครับ

เช่น
-id
-title
-link <<< เพิ่มเข้าไป

link  ไว้เก็บ url ไปเลย  :wanwan020:

ก่อนจะ query เข้าไปก็แปลงชักหน่อย

$url = strtolower(str_replace(" ","-",$url));
$url = strtolower(preg_replace('~[^a-z0-9ก-๙\.\-\_]~iu','',$url));
$url = urlencode($url);

mysql_query('...'); อะไรว่าไป
แค่เนียก็จะได้ Link ที่เป็น URL แล้ว



xvlnw.com

อ้างถึงจาก: zunkz ใน 15 มกราคม 2010, 12:29:01
:wanwan014:

เพื่ม db อีก 1 แถว ครับ

เช่น
-id
-title
-link <<< เพิ่มเข้าไป

link  ไว้เก็บ url ไปเลย  :wanwan020:

ก่อนจะ query เข้าไปก็แปลงชักหน่อย

$url = strtolower(str_replace(" ","-",$url));
$url = strtolower(preg_replace('~[^a-z0-9ก-๙\.\-\_]~iu','',$url));
$url = urlencode($url);

mysql_query('...'); อะไรว่าไป
แค่เนียก็จะได้ Link ที่เป็น URL แล้ว




ขอบคุณมากครับ ได้แนวคิดดี ๆ แล้ว อิอิ +1
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

bird35793

[direct=http://www.thehddrecovery.com]HDD recovery[/direct]