WIFIHELL - 科技改变生活

 找回密码
 注册WIFIHELL

QQ登录

只需一步,快速开始

开启左侧

Discuz在LNMP环境下的正确URL静态化方法

[复制链接]
222ba 发表于 2013-10-4 09:41:25 | 显示全部楼层 |阅读模式

注册WIFIHELL,浏览更多技术贴!

您需要 登录 才可以下载或查看,没有账号?注册WIFIHELL

x
URL 静态化可以提高搜索引擎抓取,开启本功能需要对 Web 服务器增加相应的 Rewrite 支持,且会轻微增加服务器负担。同时您还可以调整每个页面的静态格式,但不得删除其中的标记,重置静态格式请留空。注意,修改静态格式后您需要修改服务器的 Rewrite 规则设置
  1. Apache Web Server(独立主机用户)
  2. <IfModule mod_rewrite.c>
  3.         RewriteEngine On
  4.         RewriteCond %{QUERY_STRING} ^(.*)$
  5.         RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
  6.         RewriteCond %{QUERY_STRING} ^(.*)$
  7.         RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
  8.         RewriteCond %{QUERY_STRING} ^(.*)$
  9.         RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
  10.         RewriteCond %{QUERY_STRING} ^(.*)$
  11.         RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
  12.         RewriteCond %{QUERY_STRING} ^(.*)$
  13.         RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
  14.         RewriteCond %{QUERY_STRING} ^(.*)$
  15.         RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
  16.         RewriteCond %{QUERY_STRING} ^(.*)$
  17.         RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
  18.         RewriteCond %{QUERY_STRING} ^(.*)$
  19.         RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1
  20.         RewriteCond %{QUERY_STRING} ^(.*)$
  21.         RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3&%1
  22. </IfModule>
  23. Apache Web Server(虚拟主机用户)
  24. # 将 RewriteEngine 模式打开
  25. RewriteEngine On

  26. # 修改以下语句中的 /discuz 为您的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 /
  27. RewriteBase /discuz

  28. # Rewrite 系统规则请勿修改
  29. RewriteCond %{QUERY_STRING} ^(.*)$
  30. RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
  31. RewriteCond %{QUERY_STRING} ^(.*)$
  32. RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
  33. RewriteCond %{QUERY_STRING} ^(.*)$
  34. RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
  35. RewriteCond %{QUERY_STRING} ^(.*)$
  36. RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
  37. RewriteCond %{QUERY_STRING} ^(.*)$
  38. RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
  39. RewriteCond %{QUERY_STRING} ^(.*)$
  40. RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
  41. RewriteCond %{QUERY_STRING} ^(.*)$
  42. RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
  43. RewriteCond %{QUERY_STRING} ^(.*)$
  44. RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
  45. RewriteCond %{QUERY_STRING} ^(.*)$
  46. RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1

  47. IIS Web Server(独立主机用户)
  48. [ISAPI_Rewrite]

  49. # 3600 = 1 hour
  50. CacheClockRate 3600

  51. RepeatLimit 32

  52. # Protect httpd.ini and httpd.parse.errors files
  53. # from accessing through HTTP
  54. RewriteRule ^(.*)/topic-(.+)\.html(\?(.*))*$ $1/portal\.php\?mod=topic&topic=$2&$4
  55. RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5
  56. RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5
  57. RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6
  58. RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=group&fid=$2&page=$3&$5
  59. RewriteRule ^(.*)/space-(username|uid)-(.+)\.html(\?(.*))*$ $1/home\.php\?mod=space&$2=$3&$5
  60. RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/home\.php\?mod=space&uid=$2&do=blog&id=$3&$5
  61. RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html(\?(.*))*$ $1/index\.php\?action=$2&value=$3&$5
  62. RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html(\?(.*))*$ $1/plugin\.php\?id=$2:$3&$5

  63. IIS7 Web Server(独立主机用户)
  64. <rewrite>
  65.         <rules>
  66.                 <rule name="portal_topic">
  67.                         <match url="^(.*/)*topic-(.+).html\?*(.*)$" />
  68.                         <action type="Rewrite" url="{R:1}/portal.php\?mod=topic&topic={R:2}&{R:3}" />
  69.                 </rule>
  70.                 <rule name="portal_article">
  71.                         <match url="^(.*/)*article-([0-9]+)-([0-9]+).html\?*(.*)$" />
  72.                         <action type="Rewrite" url="{R:1}/portal.php\?mod=view&aid={R:2}&page={R:3}&{R:4}" />
  73.                 </rule>
  74.                 <rule name="forum_forumdisplay">
  75.                         <match url="^(.*/)*forum-(\w+)-([0-9]+).html\?*(.*)$" />
  76.                         <action type="Rewrite" url="{R:1}/forum.php\?mod=forumdisplay&fid={R:2}&page={R:3}&{R:4}" />
  77.                 </rule>
  78.                 <rule name="forum_viewthread">
  79.                         <match url="^(.*/)*thread-([0-9]+)-([0-9]+)-([0-9]+).html\?*(.*)$" />
  80.                         <action type="Rewrite" url="{R:1}/forum.php\?mod=viewthread&tid={R:2}&extra=page%3D{R:4}&page={R:3}&{R:5}" />
  81.                 </rule>
  82.                 <rule name="group_group">
  83.                         <match url="^(.*/)*group-([0-9]+)-([0-9]+).html\?*(.*)$" />
  84.                         <action type="Rewrite" url="{R:1}/forum.php\?mod=group&fid={R:2}&page={R:3}&{R:4}" />
  85.                 </rule>
  86.                 <rule name="home_space">
  87.                         <match url="^(.*/)*space-(username|uid)-(.+).html\?*(.*)$" />
  88.                         <action type="Rewrite" url="{R:1}/home.php\?mod=space&{R:2}={R:3}&{R:4}" />
  89.                 </rule>
  90.                 <rule name="home_blog">
  91.                         <match url="^(.*/)*blog-([0-9]+)-([0-9]+).html\?*(.*)$" />
  92.                         <action type="Rewrite" url="{R:1}/home.php\?mod=space&uid={R:2}&do=blog&id={R:3}&{R:4}" />
  93.                 </rule>
  94.                 <rule name="forum_archiver">
  95.                         <match url="^(.*/)*(fid|tid)-([0-9]+).html\?*(.*)$" />
  96.                         <action type="Rewrite" url="{R:1}/index.php\?action={R:2}&value={R:3}&{R:4}" />
  97.                 </rule>
  98.                 <rule name="plugin">
  99.                         <match url="^(.*/)*([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+).html\?*(.*)$" />
  100.                         <action type="Rewrite" url="{R:1}/plugin.php\?id={R:2}:{R:3}&{R:4}" />
  101.                 </rule>
  102.         </rules>
  103. </rewrite>
  104. Zeus Web Server
  105. match URL into $ with ^(.*)/topic-(.+)\.html\?*(.*)$
  106. if matched then
  107.         set URL = $1/portal.php?mod=topic&topic=$2&$3
  108. endif
  109. match URL into $ with ^(.*)/article-([0-9]+)-([0-9]+)\.html\?*(.*)$
  110. if matched then
  111.         set URL = $1/portal.php?mod=view&aid=$2&page=$3&$4
  112. endif
  113. match URL into $ with ^(.*)/forum-(\w+)-([0-9]+)\.html\?*(.*)$
  114. if matched then
  115.         set URL = $1/forum.php?mod=forumdisplay&fid=$2&page=$3&$4
  116. endif
  117. match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html\?*(.*)$
  118. if matched then
  119.         set URL = $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$5
  120. endif
  121. match URL into $ with ^(.*)/group-([0-9]+)-([0-9]+)\.html\?*(.*)$
  122. if matched then
  123.         set URL = $1/forum.php?mod=group&fid=$2&page=$3&$4
  124. endif
  125. match URL into $ with ^(.*)/space-(username|uid)-(.+)\.html\?*(.*)$
  126. if matched then
  127.         set URL = $1/home.php?mod=space&$2=$3&$4
  128. endif
  129. match URL into $ with ^(.*)/blog-([0-9]+)-([0-9]+)\.html\?*(.*)$
  130. if matched then
  131.         set URL = $1/home.php?mod=space&uid=$2&do=blog&id=$3&$4
  132. endif
  133. match URL into $ with ^(.*)/(fid|tid)-([0-9]+)\.html\?*(.*)$
  134. if matched then
  135.         set URL = $1/index.php?action=$2&value=$3&$4
  136. endif
  137. match URL into $ with ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html\?*(.*)$
  138. if matched then
  139.         set URL = $1/plugin.php?id=$2:$3&$4
  140. endif

  141. Nginx Web Server
  142. rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  143. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  144. rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  145. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
  146. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  147. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  148. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
  149. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
  150. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
  151. if (!-e $request_filename) {
  152.         return 404;
  153. }
复制代码
在LNMP环境下,静态化规则已经在添加域名的时候包含在了配置文件内。因此需要修改/usr/local/nginx/conf/discuz.conf。

原始文件:

  1. location / {
  2.             rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
  3.             rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
  4.             rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page%3D$3&page=$2 last;
  5.             rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
  6.             rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
  7.         }
复制代码
新的文件:

  1. location / {
  2. rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  3. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  4. rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  5. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
  6. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  7. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  8. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
  9. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
  10. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
  11. if (!-e $request_filename) {
  12.         return 404;
  13. }

  14.         }
复制代码
最后重启lnmp,或者重启服务器。
WIFIHELL | 万丰乐活 2020开启新的征程,好货不断!
关闭

站点推荐上一条 /1 下一条

万丰乐活

GMT+8, 2024-4-19 08:42

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表