htaccess Rewrite SEO URL for Discuz Forum
Files to be modified: 02 ( function_core.php and .htaccess )1. Open : /source/function/function_core.php
Finddefine('DISCUZ_CORE_FUNCTION', true);Insert below it:
//Bo dau tieng viet
function locdau($value)
{
//bat dau loc dau
$locdau_in = array (
'#(A|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ằ|Ẳ|Ẵ|Ặ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ)#',
'#(B)#',
'#(C)#',
'#(D|Đ|đ)#',
'#(E|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ)#',
'#(F)#',
'#(G)#',
'#(H)#',
'#(I|Í|Ì|Ỉ|Ĩ|Ị|í|ì|ỉ|ĩ|ị)#',
'#(J)#',
'#(K)#',
'#(L)#',
'#(M)#',
'#(N)#',
'#(O|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ)#',
'#(P)#',
'#(Q)#',
'#(R)#',
'#(S)#',
'#(T)#',
'#(U|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự)#',
'#(V)#',
'#(W)#',
'#(X)#',
'#(Ý|Ỳ|Ỷ|Ỹ|Ỵ|Y|ý|ỳ|ỷ|ỹ|ỵ|y)#',
'#(Z)#',
"/[^a-zA-Z0-9\-\_]/",
'#(@)#',
) ;
$locdau_out = array (
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'-',
'-',
) ;
$value = preg_replace($locdau_in, $locdau_out, $value);
$value = preg_replace('/(-)+/', '-', $value);
$value = str_replace(array('-quot', '"'), '', $value);
//ket thuc loc dau
return $value;
}
Find:
function rewriteoutput($type, $returntype, $host) {
global $_G;
$fextra = '';
if($type == 'forum_forumdisplay') {
list(,,, $fid, $page, $extra) = func_get_args();
$r = array(
'{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
'{page}' => $page ? $page : 1,
//SEO-URL (c) Vic.0
'{tenbox}' => locdau(DB::result_first("SELECT name FROM ".DB::table('forum_forum')." WHERE fid='$fid'")),
//End SEO-URL
);
} elseif($type == 'forum_viewthread') {
list(,,, $tid, $page, $prevpage, $extra) = func_get_args();
$r = array(
'{tid}' => $tid,
'{page}' => $page ? $page : 1,
'{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
//SEO-URL (c) Vic.0
'{tenbai}' => locdau(DB::result_first("SELECT subject FROM ".DB::table('forum_thread')." WHERE tid='$tid'")),
//End SEO-URL
);
} elseif($type == 'home_space') {
list(,,, $uid, $username, $extra) = func_get_args();
$_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
$r = array(
'{user}' => $uid ? 'uid' : 'username',
'{value}' => $uid ? $uid : $username,
);
} elseif($type == 'home_blog') {
list(,,, $uid, $blogid, $extra) = func_get_args();
$r = array(
'{uid}' => $uid,
'{blogid}' => $blogid,
);
} elseif($type == 'group_group') {
list(,,, $fid, $page, $extra) = func_get_args();
$r = array(
'{fid}' => $fid,
'{page}' => $page ? $page : 1,
);
} elseif($type == 'portal_topic') {
list(,,, $name, $extra) = func_get_args();
$r = array(
'{name}' => $name,
);
} elseif($type == 'portal_article') {
list(,,, $id, $page, $extra) = func_get_args();
$r = array(
'{id}' => $id,
'{page}' => $page ? $page : 1,
);
} elseif($type == 'forum_archiver') {
list(,, $action, $value, $page, $extra) = func_get_args();
$host = '';
$r = array(
'{action}' => $action,
'{value}' => $value,
);
if($page) {
$fextra = '?page='.$page;
}
} elseif($type == 'plugin') {
list(,, $pluginid, $module,, $param, $extra) = func_get_args();
$host = '';
$r = array(
'{pluginid}' => $pluginid,
'{module}' => $module,
);
if($param) {
$fextra = '?'.$param;
}
}
$href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;
if(!$returntype) {
return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';
} else {
return $host.$href;
}
}
Replaced by:
function rewriteoutput($type, $returntype, $host) {
global $_G;
$fextra = '';
if($type == 'forum_forumdisplay') {
list(,,, $fid, $page, $extra) = func_get_args();
$r = array(
'{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
'{page}' => $page ? $page : 1,
'{tenbox}' => locdau(DB::result_first("SELECT name FROM ".DB::table('forum_forum')." WHERE fid='$fid'")),
);
} elseif($type == 'forum_viewthread') {
list(,,, $tid, $page, $prevpage, $extra) = func_get_args();
$r = array(
'{tid}' => $tid,
'{page}' => $page ? $page : 1,
'{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
'{tenbai}' => locdau(DB::result_first("SELECT subject FROM ".DB::table('forum_thread')." WHERE tid='$tid'")),
);
} elseif($type == 'home_space') {
list(,,, $uid, $username, $extra) = func_get_args();
$_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
$r = array(
'{user}' => $uid ? 'uid' : 'username',
'{value}' => $uid ? $uid : $username,
'{nick}' => DB::result_first("SELECT username FROM ".DB::table('common_member')." WHERE uid='$uid'"),
);
} elseif($type == 'home_blog') {
list(,,, $uid, $blogid, $extra) = func_get_args();
$r = array(
'{uid}' => $uid,
'{blogid}' => $blogid,
'{tenblog}' => locdau(DB::result_first("SELECT subject FROM ".DB::table('home_blog')." WHERE blogid='$blogid'")),
);
} elseif($type == 'group_group') {
list(,,, $fid, $page, $extra) = func_get_args();
$r = array(
'{fid}' => $fid,
'{page}' => $page ? $page : 1,
);
} elseif($type == 'portal_topic') {
list(,,, $name, $extra) = func_get_args();
$r = array(
'{name}' => $name,
);
} elseif($type == 'portal_article') {
list(,,, $id, $page, $extra) = func_get_args();
$r = array(
'{id}' => $id,
'{page}' => $page ? $page : 1,
);
} elseif($type == 'forum_archiver') {
list(,, $action, $value, $page, $extra) = func_get_args();
$host = '';
$r = array(
'{action}' => $action,
'{value}' => $value,
);
if($page) {
$fextra = '?page='.$page;
}
}
$href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;
if(!$returntype) {
return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';
} else {
return $host.$href;
}
}
2. Configure .htaccess file like this :
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^article-(+)-(+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(\w+)/(+)$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^thread/(.*)-(+)-(+)-(+)\.html$ forum.php?mod=viewthread&tid=$2&$3&page=$3&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^group-(+)-(+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^blog/{tenblog}-(+)-(+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^archiver/(fid|tid)-(+)\.html$ archiver/index.php?action=$1&value=$2&%1
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(+*)-(+)\.html$ plugin.php?id=$1:$2&%1
3. Login AdminCP --> Global --> SEO --> SEO settings: Enable
4. Upload files & update cache
This mod still works with Discuz! X 3.5 for Vietnamese title SEO URL :handshake
Page:
[1]