Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[求助] Discuz!系列教程-通过判断空间类型选择伪静态方式

  [复制链接]
crx349 发表于 2013-1-6 01:45:42 | 显示全部楼层 |阅读模式
本帖最后由 crx349 于 2015-6-1 10:20 编辑

本教程由crx349首发,转载请注明首发作者:crx349


程序版本:Discuz!x1.5-x3.1
目的:给新手认清空间类型,从而选择合适的伪静态方式
适合人群:使用Discuz!x1.5-x3.1的站长

具体内容:
1.后台,登录,首页会看到这样的一张图:

2.仔细看这内容:

服务器系统及 PHP、服务器软件

可能的组合有:
(1)服务器系统及 PHP:WINNT / PHP v5.X.X  服务器软件:Microsoft-IIS/6.0
这时候选择的伪静态规则对应的是:IIS Web Server(独立主机用户)
  1. [ISAPI_Rewrite]

  2. # 3600 = 1 hour
  3. CacheClockRate 3600

  4. RepeatLimit 32

  5. # Protect httpd.ini and httpd.parse.errors files
  6. # from accessing through HTTP
  7. RewriteRule ^(.*)/topic-(.+)\.html(\?(.*))*$ $1/portal\.php\?mod=topic&topic=$2&$4
  8. RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/portal\.php\?mod=view&aid=$2&page=$3&$5
  9. RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=forumdisplay&fid=$2&page=$3&$5
  10. RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&$6
  11. RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/forum\.php\?mod=group&fid=$2&page=$3&$5
  12. RewriteRule ^(.*)/space-(username|uid)-(.+)\.html(\?(.*))*$ $1/home\.php\?mod=space&$2=$3&$5
  13. RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html(\?(.*))*$ $1/home\.php\?mod=space&uid=$2&do=blog&id=$3&$5
  14. RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html(\?(.*))*$ $1/index\.php\?action=$2&value=$3&$5
  15. RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html(\?(.*))*$ $1/plugin\.php\?id=$2:$3&$5
复制代码
将以上内容保存为httpd.ini 上传到网站根目录
(2)服务器系统及 PHP:WINNT / PHP v5.2.16  服务器软件:Microsoft-IIS/7.X
这时候选择的伪静态规则对应的是:IIS7 Web Server(独立主机用户)
规则文件:
备注:对应虚拟空间的用户上传这个规则就可以了,如果空间商有自定义规则方式需要和空间商客服核实下(万网是自定义规则)或者可以QQ咨询。如果是独立主机涉及到伪静态组件设置,就不在这里另外说明了。

(3)服务器系统及 PHP : Linux / PHP v5.X.X  服务器软件:Apache
这时候选择的伪静态规则对应的是:Apache Web Server(虚拟主机用户)
  1. # 将 RewriteEngine 模式打开
  2. RewriteEngine On

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

  5. # Rewrite 系统规则请勿修改
  6. RewriteCond %{QUERY_STRING} ^(.*)$
  7. RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1
  8. RewriteCond %{QUERY_STRING} ^(.*)$
  9. RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1
  10. RewriteCond %{QUERY_STRING} ^(.*)$
  11. RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1
  12. RewriteCond %{QUERY_STRING} ^(.*)$
  13. RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1
  14. RewriteCond %{QUERY_STRING} ^(.*)$
  15. RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1
  16. RewriteCond %{QUERY_STRING} ^(.*)$
  17. RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1
  18. RewriteCond %{QUERY_STRING} ^(.*)$
  19. RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1
  20. RewriteCond %{QUERY_STRING} ^(.*)$
  21. RewriteRule ^archiver/(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1
  22. RewriteCond %{QUERY_STRING} ^(.*)$
  23. RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1
复制代码
以上规则具体如何使用见https://discuz.dismall.com/thread-3191754-1-1.html

这时候会有人有疑问了:
如果是独立Linux服务器用什么规则

如果是独立主机会有独立的httpd-vhosts.conf配置文件,可以在这个文件的网站配置字段中加入:
  1. <IfModule mod_rewrite.c>
  2.         RewriteEngine On
  3.         RewriteCond %{QUERY_STRING} ^(.*)$
  4.         RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
  5.         RewriteCond %{QUERY_STRING} ^(.*)$
  6.         RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
  7.         RewriteCond %{QUERY_STRING} ^(.*)$
  8.         RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
  9.         RewriteCond %{QUERY_STRING} ^(.*)$
  10.         RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
  11.         RewriteCond %{QUERY_STRING} ^(.*)$
  12.         RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
  13.         RewriteCond %{QUERY_STRING} ^(.*)$
  14.         RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
  15.         RewriteCond %{QUERY_STRING} ^(.*)$
  16.         RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
  17.         RewriteCond %{QUERY_STRING} ^(.*)$
  18.         RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1
  19.         RewriteCond %{QUERY_STRING} ^(.*)$
  20.         RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3&%1
  21. </IfModule>
复制代码
这些规则内容。
一个案例:
  1. <VirtualHost *:80>
  2. DocumentRoot /home/xmspace
  3. ServerName [url]www.xmspace.net[/url]
  4. <IfModule mod_rewrite.c>
  5.         RewriteEngine On
  6.         RewriteCond %{QUERY_STRING} ^(.*)$
  7.         RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
  8.         RewriteCond %{QUERY_STRING} ^(.*)$
  9.         RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
  10.         RewriteCond %{QUERY_STRING} ^(.*)$
  11.         RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
  12.         RewriteCond %{QUERY_STRING} ^(.*)$
  13.         RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
  14.         RewriteCond %{QUERY_STRING} ^(.*)$
  15.         RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
  16.         RewriteCond %{QUERY_STRING} ^(.*)$
  17.         RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
  18.         RewriteCond %{QUERY_STRING} ^(.*)$
  19.         RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
  20.         RewriteCond %{QUERY_STRING} ^(.*)$
  21.         RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1
  22.         RewriteCond %{QUERY_STRING} ^(.*)$
  23.         RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3&%1
  24. </IfModule>
  25. </VirtualHost>
复制代码
(4)服务器系统及 PHP : Linux / PHP v5.X.X  服务器软件:Nginx
这时候选择的伪静态规则对应的是:Nginx Web Server
如果选择的是独立服务器下面给一个案例:

vi /usr/local/nginx/conf/nginx.conf #编辑nginx配置文件
找到下面这行,在server_name localhost;后边一行添加上面的代码
  1. server {
  2. listen 80;
  3. server_name localhost;
  4. rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  5. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  6. rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  7. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
  8. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  9. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  10. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
  11. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
  12. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
  13. if (!-e $request_filename) {
  14.         return 404;
  15. }

  16. #access_log logs/host.access.log main;
  17. location / {
  18. root html;
  19. index index.php index.html index.htm;
  20. }
复制代码
如果是虚拟主机一般支持.htaccess

直接将:
  1. rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
  2. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
  3. rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
  4. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
  5. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
  6. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
  7. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
  8. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
  9. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
  10. if (!-e $request_filename) {
  11.         return 404;
  12. }
复制代码
保存为.htaccess上传网站根目录,再测试是否成功,由于各家空间商的规则设置方式不同,有些使用的是自己的后台空间管理界面设置,所以在使用时还是咨询下空间商客服。

最后一种是Zeus Web Server模式,这个由于使用相对较少,如遇到可以直接咨询空间商或QQ我

以上就是如果给新手用于判断空间类型,选择合适伪静态教程。

本教程本人独家撰写,转载请注明作者和地址,谢谢!

本帖子中包含更多资源

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

x

评分

7

查看全部评分

。See_you_tomor 发表于 2013-1-6 01:56:27 | 显示全部楼层
谢谢分享~~~
回复

使用道具 举报

misskao 发表于 2013-1-6 10:25:21 | 显示全部楼层
很棒...謝謝分享
回复

使用道具 举报

 楼主| crx349 发表于 2013-1-6 11:18:15 | 显示全部楼层
谢谢支持 你们的支持将是我写好教程的动力啊
回复

使用道具 举报

KiSsゞ 发表于 2013-1-6 11:18:24 | 显示全部楼层
支持下哈,好长,没怎么看..
回复

使用道具 举报

风乱流年 发表于 2013-1-6 11:18:27 | 显示全部楼层
前排纯支持
回复

使用道具 举报

jackxx 发表于 2013-1-6 11:28:27 | 显示全部楼层
不错,值得学习,谢谢分享。。。
回复

使用道具 举报

低着头走路 发表于 2013-1-6 11:41:28 | 显示全部楼层
谢谢分享
回复

使用道具 举报

ARCHY` 发表于 2013-1-6 11:44:05 | 显示全部楼层
前排支持下了
回复

使用道具 举报

dicky57 发表于 2013-1-6 14:37:16 | 显示全部楼层
感謝您的熱情分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-4-25 17:45 , Processed in 0.119656 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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