ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: webdevils ที่ 30 ตุลาคม 2008, 02:59:27



หัวข้อ: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: webdevils ที่ 30 ตุลาคม 2008, 02:59:27
pligg นี้จะทำให้ url อ่านออกเป็นภาษาไทยนี้ทำยังไงหรอครับ ต้องแก้ที่ .htaccess ใช่ไหมครับ แล้วก็ title rss ของมันก้อ่านไม่ออก อ่านไทยไม่ได้ด้วยครับ พี่ๆช่วยผมหน่อยครับได้โปรด :'(



อันนี้ไฟล์ htaccess นะครับ


โค๊ด:
##### Gzip Begin #####
## To enable Gzip and decrease the load times of your Pligg site
## change /home/path/to to your absolute server path and remove the two # from both lines
## php_value auto_prepend_file /home/path/to/begin_gzip.php
## php_value auto_append_file /home/path/to/end_gzip.php

## AddType "text/javascript" .gz
## AddEncoding gzip .gz
## RewriteCond %{HTTP:Accept-encoding} gzip
## RewriteCond %{THE_REQUEST} ^(.*).js
## RewriteCond %{SCRIPT_FILENAME}.gz -f
## RewriteRule ^(.*)\.js $1.js.gz [L]
##### Gzip End #####

##### 404 Error Begin #####
## If Pligg is installed in a subfolder, change the below line to ErrorDocument 404 /name-of-subfolder/404error.php
ErrorDocument 404 /404error.php
##### 404 Error End #####

##### Re-directing Begin #####
Options +Indexes +FollowSymlinks -MultiViews
RewriteEngine on
## If Pligg is installed in a subfolder, change the below line to RewriteBase /name-of-subfolder
RewriteBase /
## If installed in a subfolder you may need to add ## to the beginning of the next line
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/

## Remove these two lines if you have a sub-domain like  http://ashdigg.pligg.com  or http://localhost
## Keep if your site it like   http://www.pligg.com
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^\/?(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
##### Re-directing End #####

##### You can find the below lines pre-made for you in the category management section of the admin panel ######
RewriteRule ^(all|pligg)/([^/]+)/?$ story.php?title=$2 [L]
RewriteRule ^(all|pligg)/?$ ?category=$1 [L]
#####

##### URL Method 2 ("Clean" URLs) Begin #####
RewriteRule ^story/([0-9]+)/?$ story.php?id=$1 [L]
RewriteRule ^story/title/([^/]+)/?$ story.php?title=$1 [L]
RewriteRule ^story/([0-9]+)/editcomment/([0-9]+)/?$ edit.php?id=$1&commentid=$2
RewriteRule ^story/([0-9]+)/edit/?$ editlink.php?id=$1
RewriteRule ^story/([0-9]+)/modify/([a-z]+)/?$ linkadmin.php?id=$1&action=$2
RewriteRule ^recommend/([a-zA-Z0-9-]+)/?$ recommend.php?id=$1 [L]
RewriteRule ^category/([^/]+)/?$ index.php?category=$1 [L]
RewriteRule ^upcoming/category/([^/]+)/?$ upcoming.php?category=$1 [L]
RewriteRule ^upcoming/([a-zA-Z0-9]+)/?$ upcoming.php?part=upcoming&order=$1
RewriteRule ^inbox/?$ user.php?view=inbox
RewriteRule ^user/?$ user.php
RewriteRule ^user/view/([a-zA-Z0-9-]+)/?$ user.php?view=$1
RewriteRule ^user/view/([a-zA-Z0-9+]+)/([a-zA-Z0-9+]+)/?$ user.php?view=$1&login=$2
RewriteRule ^user/view/([a-zA-Z0-9+]+)/login/([a-zA-Z0-9+]+)/?$ user.php?view=$1&login=$2
RewriteRule ^user/([a-zA-Z-]+)/link/([0-9+]+)/?$ user_add_remove_links.php?action=$1&link=$2
RewriteRule ^published/?$ index.php
RewriteRule ^published/([a-zA-Z0-9-]+)/?$ index.php?part=$1
RewriteRule ^published/([a-zA-Z0-9-]+)/category/([a-zA-Z0-9_-]+)/?$ index.php?part=$1&category=$2
RewriteRule ^upcoming/([a-zA-Z0-9-]+)/category/([a-zA-Z0-9_-]+)/?$ upcoming.php?part=upcoming&order=$1&category=$2
RewriteRule ^search/(.+)/?$ search.php?search=$1
RewriteRule ^searchurl/(.+)/?$ search.php?url=$1
RewriteRule ^login/?$ login.php
RewriteRule ^login/([a-zA-Z0-9-]+)/?$ login.php?return=$1
RewriteRule ^login/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ login.php?return=$1/$2
RewriteRule ^register/?$ register.php
RewriteRule ^topusers/?$ topusers.php
RewriteRule ^about/([a-zA-Z0-9-]+)/?$ faq-$1.php
RewriteRule ^upcoming/?$ upcoming.php
RewriteRule ^submit/?$ submit.php
RewriteRule ^rss/?$ rss.php
RewriteRule ^rss/([a-zA-Z0-9-]+)/?$ rss.php?status=$1
RewriteRule ^rss/category/([a-zA-Z0-9_-]+)/?$ rss.php?category=$1
RewriteRule ^rss/search/([a-zA-Z0-9-]+)/?$ rss.php?search=$1
RewriteRule ^rss/user/([a-zA-Z0-9-]+)/?$ rss.php?user=$1
RewriteRule ^rss/user/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ userrss.php?user=$1&status=$2
RewriteRule ^trackback/([0-9]+)/?$ trackback.php?id=$1
RewriteRule ^profile/?$ profile.php
RewriteRule ^admin/?$ admin_index.php
RewriteRule ^tagcloud/?$ cloud.php
RewriteRule ^tagcloud/range/([0-9]+)/?$ cloud.php?range=$1 [L]
RewriteRule ^tag/(.+)/(.+)/?$ search.php?search=$1&tag=true&from=$2 [QSA,NC,L]
RewriteRule ^tag/(.+)/?$ search.php?search=$1&tag=true [QSA,NC,L]
RewriteRule ^live/?$ live.php
RewriteRule ^out/([^/]+)/?$ out.php?title=$1 [L]
RewriteRule ^settemplate/?$ settemplate.php
RewriteRule ^comments/?$ live_comments.php
RewriteRule ^live_published/?$ live_published.php
RewriteRule ^unpublished/?$ live_unpublished.php
RewriteRule ^logout/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ login.php?op=logout&return=$1/$2
RewriteRule ^published/page/([^/]+)/?$ index.php?page=$1 [L]
RewriteRule ^published/page/([^/]+)/category/([^/]+)/?$ index.php?page=$1&category=$2 [L]
RewriteRule ^published/page/([^/]+)/([^/]+)category/([^/]+)/?$ index.php?page=$1&part=$2&category=$3 [L]
RewriteRule ^upcoming/page/([0-9]+)/?$ upcoming.php?page=$1 [L]
RewriteRule ^upcoming/page/([^/]+)/category/([^/]+)/?$ upcoming.php?page=$1&category=$2 [L]
RewriteRule ^upcoming/page/([^/]+)/upcoming/([^/]+)/?$ upcoming.php?page=$1&part=upcoming&order=$2 [L]
RewriteRule ^upcoming/page/([^/]+)/upcoming=([^/]+)category/([^/]+)/?$ upcoming.php?page=$1&part=upcoming&order=$2&category=$3 [L]
RewriteRule ^topusers/page/([^/]+)/?$ topusers.php?page=$1 [L]
RewriteRule ^topusers/page/([^/]+)/sortby/([^/]+)?$ topusers.php?page=$1&sortby=$2 [L]
RewriteRule ^admin_links/page/([^/]+)/?$ admin_links.php?page=$1
RewriteRule ^admin_comments/page/([^/]+)/?$ admin_comments.php?page=$1
RewriteRule ^admin_users/page/([^/]+)/?$ admin_users.php?page=$1
RewriteRule ^comments/page/([^/]+)/?$ live_comments.php?page=$1 [L]
RewriteRule ^published/page/([^/]+)/?$ live_published.php?page=$1 [L]
RewriteRule ^unpublished/page/([^/]+)/?$ live_unpublished.php?page=$1 [L]
RewriteRule ^published/page/([^/]+)/([^/]+)/?$ index.php?page=$1&part=$2 [L]
RewriteRule ^published/page/([^/]+)/range/([^/]+)/?$ ?page=$1&range=$2 [L]
RewriteRule ^search/page/([^/]+)/search/([^/]+)/?$ search.php?page=$1&search=$2 [QSA,NC,L]
RewriteRule ^user/page/([^/]+)/([^/]+)/([^/]+)/?$ user.php?page=$1&view=$2&login=$3 [L]
RewriteRule ^statistics/page/([^/]+)/?$ module.php?module=pagestatistics&page=$1
RewriteRule ^view/([^/]+)/?$ admin_users.php?mode=view&user=$1
##### URL Method 2 ("Clean" URLs) End #####


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: iday0 ที่ 30 ตุลาคม 2008, 03:00:47
มารอคำตอบเหมือนกันครับ อิอิ


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: webdevils ที่ 30 ตุลาคม 2008, 03:08:31
ผมลองทำตามนี้แล้ว มันก็ัยังอ่านไทยไม่ออกเหมือนกันครับ http://forums.pligg.com/wiki-articles/8594-url-method.html


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: webdevils ที่ 30 ตุลาคม 2008, 19:02:13
พอมีคนทราบบ้างไหมครับ จะแก้ยังไง   ที่สำคัญrss มันขึ้นtitle เป็นภาษามั้วๆนี้แก้ครับ :'( :'( :'(


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: บอท! ที่ 30 ตุลาคม 2008, 19:18:58
ดัน ๆ อยากรู้ด้วย
วางแปลนว่าจะทำ


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: net1 ที่ 30 ตุลาคม 2008, 19:33:08
น่าจะต้องแก้ที่ตัวโปรแกรมให้สามารถรับค่าเป็น utf-8 ได้ หรือ สร้าง ลิงค์ให้เป็น utf-8


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: ummimp ที่ 30 ตุลาคม 2008, 20:20:48
มีใครทำได้ ช่วยบอกด้วยครับ  :P


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: flukenakrab ที่ 31 ตุลาคม 2008, 01:19:34
พอมีคนทราบบ้างไหมครับ จะแก้ยังไง   ที่สำคัญrss มันขึ้นtitle เป็นภาษามั้วๆนี้แก้ครับ :'( :'( :'(

rss ผมก็เป็นครับ  แต่ตรง url ไม่เป็นนะครับ


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: movemore ที่ 31 ตุลาคม 2008, 01:21:23
๐-ฮ


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: EThaiZone ที่ 31 ตุลาคม 2008, 02:01:48
๐-ฮ

มันต้อง ก-๙ ครับ

โค๊ด:
http://www.fileformat.info/info/unicode/block/thai/utf8test.htm

สำหรับ pligg งานนี้บอกเลยไ้ด้เลย มันยาว  :P


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: janeos ที่ 24 พฤศจิกายน 2008, 13:27:49
อ้างถึง
pligg นี้จะทำให้ url อ่านออกเป็นภาษาไทยนี้ทำยังไงหรอครับ ต้องแก้ที่ .htaccess ใช่ไหมครับ

ชื่อ story พอทำเป็นภาษาไทยได้ครับ --> http://www.dunweb.net/
แต่ชื่อ category ผมก็กำลังหาวิธีอยู่เหมือนกัน แต่ยังติดอยู่ที่ .htaccess พอใส่ภาษาไทยลงไปแล้วมัน error อ่ะครับ ???


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: บอท! ที่ 24 พฤศจิกายน 2008, 14:08:56
ส่วน category ลองไปแก้ดูเมื่อกี้ ก็ใช้ ภาษาไทยได้นะ
ว่างแล้วค่อยไปเล่นเรื่อง rss feed


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: ball6847 ที่ 24 พฤศจิกายน 2008, 14:49:05
บอลก็กำลังจะแกะ pligg เหมือนกัน

คิดว่าต้อง urlencode ภาษาไทยซะก่อน คงต้อลุยในสคริปท์เลย

edit : ดูมามันก็ encode ให้แล้วนี่หว่า  ;D


หัวข้อ: Re: URLภาษาไทย กับ Pligg
เริ่มหัวข้อโดย: ball6847 ที่ 24 พฤศจิกายน 2008, 17:29:50
1. พอเพิ่มหมวดหมู่แล้วคนที่ใช้ URLMethod2 ต้องไปแก้ .htaccess ตามที่ pligg เจนให้ด้านล่าง อันนี้คิดว่าคนที่เล่นอยู่คงเข้าใจอยู่แล้ว (ผมเพิ่งลองก็ไม่เข้าใจ เหอๆ)

2. ปัญหาคือพอใช้หมวดหมู่ไทยก๊อปไปวาง .htaccess แล้วมันดันเน่า
- สาเหตุมันมาจาก RewriteRule ที่ pligg มันเจนมาให้นั้นมัน encode ภาษาไทยให้เสร็จสรรพ
แต่ผมไม่ทราบสาเหตุนะ ผมลองแก้ชื่อหมวดหมู่ให้เป็นแบบที่ไม่ได้เข้ารหัส มันดันได้ ไม่ทราบว่า apache มันเห็นเป็นแบบ encode หรือ decode แต่เครื่องผมมันเห็นแบบ decode

ทดสอบลองแก้ .htaccess จากที่ pligg มันเจนให้มา จะเห็นที่มันเข้ารหัสไว้ ลองแก้เป็นภาษาไทยแบบไม่เข้ารหัสเลย
อย่าง

โค๊ด:
RewriteRule ^(all|pligg|%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%8C%E0%B8%95%E0%B8%B9%E0%B8%99)/([^/]+)/?$ story.php?title=$2 [L]
RewriteRule ^(all|pligg|%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%8C%E0%B8%95%E0%B8%B9%E0%B8%99)/?$ ?category=$1 [L]


ก็แก้เป็น

โค๊ด:
RewriteRule ^(all|pligg|การ์ตูน)/([^/]+)/?$ story.php?title=$2 [L]
RewriteRule ^(all|pligg|การ์ตูน)/?$ ?category=$1 [L]


ทดสอบแล้วใน
- IE6 (ของโปรแกรม MultipleIE)
- IE7
- Firefox3
- Opera9
- Google Chrome


วิธีนี้มันดิบชะมัดเลยเหอๆ  :-X
- ผมไม่มีความรู้เรื่อง apache มากนะ เพราะฉะนั้นจะมีการตั้งค่าตรงไหนที่มีผลกับภาษาไทยใน .htaccess รึปล่าว ผมไม่ทราบ แต่เครื่อง localhost ผมผ่าน แล้วก็ยังไม่ได้ลองบน host จิง
- ผมใช้ editplus แก้ไฟล์ .htaccess เซฟเป็น utf-8 คนอื่นผมไม่ทราบนะว่าผลจะเป็นงัย



แต่อีกปัญหาน่าเบื่อเรื่อง encoding
ในบางเครื่องทำตามข้างบนก็อาจจะยังเน่า เพราะ pligg มันบันทึกลง database เน่าเอง

ถ้าบางคนมีปัญหากับ database ลอง ใส่ mysql_query("SET NAMES utf8;");
ในไฟล์ lib/db.php

แบบนี้มั้ง มั่วๆไป

โค๊ด:
<?php
function connect($dbuser=''$dbpassword=''$dbhost='localhost')
{
global $ezsql_mysql_str$return_val false;

// Must have a user and a password
if ( ! $dbuser )
{
$this->register_error($ezsql_mysql_str[1]);
//$this->show_errors ? trigger_error($ezsql_mysql_str[1],E_USER_WARNING) : null;
die($ezsql_mysql_str[1]);
}
// Try to establish the server database handle
else if ( ! $this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword,true) )
{
$this->register_error($ezsql_mysql_str[2].' in '.__FILE__.' on line '.__LINE__);
$this->show_errors trigger_error($ezsql_mysql_str[2],E_USER_WARNING) : null;
}
else
{
if($this->log_to_file){
$fh=fopen($this->logfile,"a");
fwrite($fh,"Connect - " date("Y-m-d H:i:s"time()) . " - " $_SERVER['REQUEST_URI'] ."\n");
fclose($fh);
}

$this->dbuser $dbuser;
$this->dbpassword $dbpassword;
$this->dbhost $dbhost;
$return_val true;

mysql_query("SET NAMES utf8;");

}

return $return_val;
}

?>

อ้อ ลืมบอกว่า ผมสร้าง db เป็น utf8 หมดนะ (ไม่รู้เกี่ยวป่าว โคตรมั่วๆๆๆๆๆ)


อีกเรื่องๆๆๆๆๆ ตอน submit url อ่ะ pligg มันจะไปดึงหน้าเว็บนั้นมาแล้วเอา title มากรอกให้เอง แล้วมันจะแปลง encoding ให้ด้วย ถ้าหน้านั้นไม่ใช้ UTF-8

แต่ ... บางเว็บใช้ 2 encoding ไม่ใกล้ไม่ไกล ไทยเสียวนี่เอง pligg มันเอาแค่อันแรก เลยกลายเป็นมันเอา UTF-8 ไปแปลงเป็น UTF-8 เหอๆ เอ๋อไปกันใหญ่ แต่ปัยหานี้ไม่น่าจะมีบ่อย ผ่านๆๆๆ

 ;D >:(