View: 53|Reply: 0

SEO url Rewrite rules for post forum name Discuz! X5.0

[Copy link]
Posted on The day before yesterday 18:22 | Show all floors |Reading mode
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 :



  1. function rewriteoutput($type, $returntype, $host) {
  2.         global $_G;
  3.         $fextra = '';
  4.         if($type == 'forum_forumdisplay') {
  5.                 [, , , $fid, $page, $extra] = func_get_args();
  6.                 $r = [
  7.                         '{fid}' => empty($_G['setting']['forumkeys'][$fid]) ? $fid : $_G['setting']['forumkeys'][$fid],
  8.                         '{page}' => $page ? $page : 1,
  9.                 ];
  10.         } elseif($type == 'forum_viewthread') {
  11.                 [, , , $tid, $page, $prevpage, $extra] = func_get_args();
  12.                 $r = [
  13.                         '{tid}' => $tid,
  14.                         '{page}' => $page ? $page : 1,
  15.                         '{prevpage}' => $prevpage && !IS_ROBOT ? $prevpage : 1,
  16.                 ];
  17.         } elseif($type == 'home_space') {
  18.                 [, , , $uid, $username, $extra] = func_get_args();
  19.                 $_G['setting']['rewritecompatible'] && $username = rawurlencode($username);
  20.                 $r = [
  21.                         '{user}' => $uid ? 'uid' : 'username',
  22.                         '{value}' => $uid ? $uid : $username,
  23.                 ];
  24.         } elseif($type == 'home_blog') {
  25.                 [, , , $uid, $blogid, $extra] = func_get_args();
  26.                 $r = [
  27.                         '{uid}' => $uid,
  28.                         '{blogid}' => $blogid,
  29.                 ];
  30.         } elseif($type == 'group_group') {
  31.                 [, , , $fid, $page, $extra] = func_get_args();
  32.                 $r = [
  33.                         '{fid}' => $fid,
  34.                         '{page}' => $page ? $page : 1,
  35.                 ];
  36.         } elseif($type == 'portal_topic') {
  37.                 [, , , $name, $extra] = func_get_args();
  38.                 $r = [
  39.                         '{name}' => $name,
  40.                 ];
  41.         } elseif($type == 'portal_article') {
  42.                 [, , , $id, $page, $extra] = func_get_args();
  43.                 $r = [
  44.                         '{id}' => $id,
  45.                         '{page}' => $page ? $page : 1,
  46.                 ];
  47.         } elseif($type == 'forum_archiver') {
  48.                 [, , $action, $value, $page, $extra] = func_get_args();
  49.                 $host = '';
  50.                 $r = [
  51.                         '{action}' => $action,
  52.                         '{value}' => $value,
  53.                 ];
  54.                 if($page) {
  55.                         $fextra = '?page='.$page;
  56.                 }
  57.         } elseif($type == 'plugin') {
  58.                 [, , $pluginid, $module, , $param, $extra] = func_get_args();
  59.                 $host = '';
  60.                 $r = [
  61.                         '{pluginid}' => $pluginid,
  62.                         '{module}' => $module,
  63.                 ];
  64.                 if($param) {
  65.                         $fextra = '?'.$param;
  66.                 }
  67.         }
  68.         $href = str_replace(array_keys($r), $r, $_G['setting']['rewriterule'][$type]).$fextra;
  69.         if(!$returntype) {
  70.                 return '<a href="'.$host.$href.'"'.(!empty($extra) ? stripslashes($extra) : '').'>';
  71.         } else {
  72.                 return $host.$href;
  73.         }
  74. }

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


  1. #forum-{forumname}-{fid}-{page}.html
  2. rewrite ^/forum-([a-zA-Z0-9\-]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$2&page=$3 last;

  3. # thread-{tid}-{subject}-{page}.html
  4. rewrite ^/thread-([0-9]+)-([a-zA-Z0-9\-]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&page=$3 last;

  5. # old version (optional)
  6. rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=forumdisplay&fid=$1&page=$2 last;
  7. rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /forum.php?mod=viewthread&tid=$1&page=$2 last;
Copy code

APACHE


  1. # forum-{forumname}-{fid}-{page}.html
  2. RewriteRule ^forum-([a-zA-Z0-9\-]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$2&page=$3 [L,QSA]

  3. # thread-{tid}-{subject}-{page}.html
  4. RewriteRule ^thread-([0-9]+)-([a-zA-Z0-9\-]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&page=$3 [L,QSA]

  5. # old version (option)
  6. RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2 [L,QSA]
  7. 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
Reply

Use item Report

You need to log in before you can reply. Login | Register

Points Rules for This Section

Close

Editors SelectedPrevious /2 Next

关注公众号
Archiver|Mobile|Darkroom|Privacy|DSC

相关侵权、举报、投诉及建议等,请发 E-mail:[email protected]

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

InThis sectionPosts
关注公众号
Back to top