|
|
By default settings in SEO of Discuz! X5.0 the rewrite rules applied for thread/topic IDs and forum IDs. But in fact , our other languages forums ( English, Brazilian, Russian...) we'll want to rewrite thread subject, forum name, category into the tiny url for sure.
Now we'll do this tiny updates for the function rewriteoutput of the file: source/function/function_core.php
The original code :
- function rewriteoutput($type, $returntype, $host) {
- global $_G;
- $fextra = '';
- if($type == 'forum_forumdisplay') {
- [, , , $fid, $page, $extra] = func_get_args();
- $r = [
- '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
- '{page}' => $page ? $page : 1,
- ];
- } elseif($type == 'forum_viewthread') {
- [, , , $tid, $page, $prevpage, $extra] = func_get_args();
- $r = [
- '{tid}' => $tid,
- '{page}' => $page ? $page : 1,
- '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
- ];
- } elseif($type == 'home_space') {
- [, , , $uid, $username, $extra] = func_get_args();
- $_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
- $r = [
- '{user}' => $uid ? 'uid' : 'username',
- '{value}' => $uid ? $uid : $username,
- ];
- } elseif($type == 'home_blog') {
- [, , , $uid, $blogid, $extra] = func_get_args();
- $r = [
- '{uid}' => $uid,
- '{blogid}' => $blogid,
- ];
- } elseif($type == 'group_group') {
- [, , , $fid, $page, $extra] = func_get_args();
- $r = [
- '{fid}' => $fid,
- '{page}' => $page ? $page : 1,
- ];
- } elseif($type == 'portal_topic') {
- [, , , $name, $extra] = func_get_args();
- $r = [
- '{name}' => $name,
- ];
- } elseif($type == 'portal_article') {
- [, , , $id, $page, $extra] = func_get_args();
- $r = [
- '{id}' => $id,
- '{page}' => $page ? $page : 1,
- ];
- } elseif($type == 'forum_archiver') {
- [, , $action, $value, $page, $extra] = func_get_args();
- $host = '';
- $r = [
- '{action}' => $action,
- '{value}' => $value,
- ];
- if($page) {
- $fextra = '?page='.$page;
- }
- } elseif($type == 'plugin') {
- [, , $pluginid, $module, , $param, $extra] = func_get_args();
- $host = '';
- $r = [
- '{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;
- }
- }
Copy code
and we make a little change in convert special characters in subject into UTF-8 standard :
After save changes for file function_core.php , We'll upload it to the server and make the SEO rules in Admin Dashboard, these settings must be matched with in rewrite of Apache/Nginx configurations:
NGINX
- #forum-{forumname}-{fid}-{page}.html
- rewrite ^/forum-([a-zA-Z0-9\-]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$2&page=$3 last;
- # thread-{tid}-{subject}-{page}.html
- rewrite ^/thread-([0-9]+)-([a-zA-Z0-9\-]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&page=$3 last;
- # old version (optional)
- rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2 last;
- rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&page=$2 last;
Copy code
APACHE
- # forum-{forumname}-{fid}-{page}.html
- RewriteRule ^forum-([a-zA-Z0-9\-]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$2&page=$3 [L,QSA]
- # thread-{tid}-{subject}-{page}.html
- RewriteRule ^thread-([0-9]+)-([a-zA-Z0-9\-]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&page=$3 [L,QSA]
- # old version (option)
- RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2 [L,QSA]
- RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&page=$2 [L,QSA]
Copy code
Have a good day with Discuz!
Purchase thread
This topic requires payment to the author 29 Points can browse
|